@Test public void testEndToEndAnswerAndFilters() { Ip ip1 = Ip.parse("1.1.1.1"); Ip ip2 = Ip.parse("2.2.2.2"); BgpPeerConfigId id1 = new BgpPeerConfigId("c1", "vrf1", ip2.toPrefix(), false); BgpActivePeerConfig peer1 = BgpActivePeerConfig.builder() .setLocalIp(ip1) .setPeerAddress(ip2) .setLocalAs(1L) .setRemoteAs(2L) .setIpv4UnicastAddressFamily(Ipv4UnicastAddressFamily.builder().build()) .build(); BgpPeerConfigId id2 = new BgpPeerConfigId("c2", "vrf2", ip1.toPrefix(), false); BgpActivePeerConfig peer2 = BgpActivePeerConfig.builder() .setLocalIp(ip2) .setPeerAddress(ip1) .setLocalAs(2L) .setRemoteAs(1L) .setIpv4UnicastAddressFamily(Ipv4UnicastAddressFamily.builder().build()) .build(); IBatfish batfish = new MockBatfish( createConfigurations(ImmutableList.of(id1, id2), ImmutableList.of(peer1, peer2))); Row.RowBuilder expectedRowBuilder = Row.builder() .put(COL_CONFIGURED_STATUS, ConfiguredSessionStatus.UNIQUE_MATCH) .put(COL_LOCAL_INTERFACE, null) .put(COL_REMOTE_INTERFACE, null) .put(COL_SESSION_TYPE, SessionType.EBGP_SINGLEHOP) .put(COL_ADDRESS_FAMILIES, ImmutableSet.of(Type.IPV4_UNICAST)); Row row1To2 = expectedRowBuilder .put(COL_LOCAL_IP, ip1) .put(COL_LOCAL_AS, 1L) .put(COL_NODE, new Node("c1")) .put(COL_REMOTE_AS, "2") .put(COL_REMOTE_NODE, new Node("c2")) .put(COL_REMOTE_IP, new SelfDescribingObject(Schema.IP, ip2)) .put(COL_VRF, "vrf1") .build(); Row row2To1 = expectedRowBuilder .put(COL_LOCAL_IP, ip2) .put(COL_LOCAL_AS, 2L) .put(COL_NODE, new Node("c2")) .put(COL_REMOTE_AS, "1") .put(COL_REMOTE_NODE, new Node("c1")) .put(COL_REMOTE_IP, new SelfDescribingObject(Schema.IP, ip1)) .put(COL_VRF, "vrf2") .build(); BgpSessionCompatibilityAnswerer answerer = new BgpSessionCompatibilityAnswerer(new BgpSessionCompatibilityQuestion(), batfish); assertThat( (TableAnswerElement) answerer.answer(batfish.getSnapshot()), hasRows(containsInAnyOrder(row1To2, row2To1))); answerer = new BgpSessionCompatibilityAnswerer( new BgpSessionCompatibilityQuestion("c1", null, null, null), batfish); assertThat( (TableAnswerElement) answerer.answer(batfish.getSnapshot()), hasRows(contains(row1To2))); answerer = new BgpSessionCompatibilityAnswerer( new BgpSessionCompatibilityQuestion(null, "c1", null, null), batfish); assertThat( (TableAnswerElement) answerer.answer(batfish.getSnapshot()), hasRows(contains(row2To1))); answerer = new BgpSessionCompatibilityAnswerer( new BgpSessionCompatibilityQuestion(null, null, "UNIQUE_MATCH", null), batfish); assertThat( (TableAnswerElement) answerer.answer(batfish.getSnapshot()), hasRows(containsInAnyOrder(row1To2, row2To1))); answerer = new BgpSessionCompatibilityAnswerer( new BgpSessionCompatibilityQuestion(null, null, "NO_LOCAL_IP", null), batfish); assertThat( (TableAnswerElement) answerer.answer(batfish.getSnapshot()), hasRows(emptyIterable())); answerer = new BgpSessionCompatibilityAnswerer( new BgpSessionCompatibilityQuestion(null, null, null, "EBGP_SINGLEHOP"), batfish); assertThat( (TableAnswerElement) answerer.answer(batfish.getSnapshot()), hasRows(containsInAnyOrder(row1To2, row2To1))); answerer = new BgpSessionCompatibilityAnswerer( new BgpSessionCompatibilityQuestion(null, null, null, "IBGP"), batfish); assertThat( (TableAnswerElement) answerer.answer(batfish.getSnapshot()), hasRows(emptyIterable())); }
@Override public AnswerElement answer(NetworkSnapshot snapshot) { BgpSessionCompatibilityQuestion question = (BgpSessionCompatibilityQuestion) _question; TableAnswerElement answer = new TableAnswerElement(BgpSessionCompatibilityAnswerer.createMetadata(question)); answer.postProcessAnswer(question, getRows(snapshot, question)); return answer; }
BgpSessionCompatibilityAnswerer extends Answerer { @Override public AnswerElement answer(NetworkSnapshot snapshot) { BgpSessionCompatibilityQuestion question = (BgpSessionCompatibilityQuestion) _question; TableAnswerElement answer = new TableAnswerElement(BgpSessionCompatibilityAnswerer.createMetadata(question)); answer.postProcessAnswer(question, getRows(snapshot, question)); return answer; } }
BgpSessionCompatibilityAnswerer extends Answerer { @Override public AnswerElement answer(NetworkSnapshot snapshot) { BgpSessionCompatibilityQuestion question = (BgpSessionCompatibilityQuestion) _question; TableAnswerElement answer = new TableAnswerElement(BgpSessionCompatibilityAnswerer.createMetadata(question)); answer.postProcessAnswer(question, getRows(snapshot, question)); return answer; } BgpSessionCompatibilityAnswerer(Question question, IBatfish batfish); }
BgpSessionCompatibilityAnswerer extends Answerer { @Override public AnswerElement answer(NetworkSnapshot snapshot) { BgpSessionCompatibilityQuestion question = (BgpSessionCompatibilityQuestion) _question; TableAnswerElement answer = new TableAnswerElement(BgpSessionCompatibilityAnswerer.createMetadata(question)); answer.postProcessAnswer(question, getRows(snapshot, question)); return answer; } BgpSessionCompatibilityAnswerer(Question question, IBatfish batfish); @Override AnswerElement answer(NetworkSnapshot snapshot); static TableMetadata createMetadata(Question question); }
BgpSessionCompatibilityAnswerer extends Answerer { @Override public AnswerElement answer(NetworkSnapshot snapshot) { BgpSessionCompatibilityQuestion question = (BgpSessionCompatibilityQuestion) _question; TableAnswerElement answer = new TableAnswerElement(BgpSessionCompatibilityAnswerer.createMetadata(question)); answer.postProcessAnswer(question, getRows(snapshot, question)); return answer; } BgpSessionCompatibilityAnswerer(Question question, IBatfish batfish); @Override AnswerElement answer(NetworkSnapshot snapshot); static TableMetadata createMetadata(Question question); static final String COL_CONFIGURED_STATUS; }