@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(); MutableValueGraph<BgpPeerConfigId, BgpSessionProperties> bgpTopology = ValueGraphBuilder.directed().allowsSelfLoops(false).build(); bgpTopology.putEdgeValue(id1, id2, BgpSessionProperties.from(peer1, peer2, false)); bgpTopology.putEdgeValue(id2, id1, BgpSessionProperties.from(peer1, peer2, true)); IBatfish batfish = new MockBatfish( createConfigurations(ImmutableList.of(id1, id2), ImmutableList.of(peer1, peer2)), new BgpTopology(bgpTopology)); Row.RowBuilder expectedRowBuilder = Row.builder() .put(COL_ESTABLISHED_STATUS, BgpSessionStatus.ESTABLISHED) .put(COL_LOCAL_INTERFACE, null) .put(COL_REMOTE_INTERFACE, null) .put(COL_ADDRESS_FAMILIES, ImmutableSet.of(Type.IPV4_UNICAST)) .put(COL_SESSION_TYPE, SessionType.EBGP_SINGLEHOP); 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(); BgpSessionStatusAnswerer answerer = new BgpSessionStatusAnswerer(new BgpSessionStatusQuestion(), batfish); assertThat( (TableAnswerElement) answerer.answer(batfish.getSnapshot()), hasRows(containsInAnyOrder(row1To2, row2To1))); answerer = new BgpSessionStatusAnswerer(new BgpSessionStatusQuestion("c1", null, null, null), batfish); assertThat( (TableAnswerElement) answerer.answer(batfish.getSnapshot()), hasRows(contains(row1To2))); answerer = new BgpSessionStatusAnswerer(new BgpSessionStatusQuestion(null, "c1", null, null), batfish); assertThat( (TableAnswerElement) answerer.answer(batfish.getSnapshot()), hasRows(contains(row2To1))); answerer = new BgpSessionStatusAnswerer( new BgpSessionStatusQuestion(null, null, "ESTABLISHED", null), batfish); assertThat( (TableAnswerElement) answerer.answer(batfish.getSnapshot()), hasRows(containsInAnyOrder(row1To2, row2To1))); answerer = new BgpSessionStatusAnswerer( new BgpSessionStatusQuestion(null, null, "NOT_ESTABLISHED", null), batfish); assertThat( (TableAnswerElement) answerer.answer(batfish.getSnapshot()), hasRows(emptyIterable())); answerer = new BgpSessionStatusAnswerer( new BgpSessionStatusQuestion(null, null, null, "EBGP_SINGLEHOP"), batfish); assertThat( (TableAnswerElement) answerer.answer(batfish.getSnapshot()), hasRows(containsInAnyOrder(row1To2, row2To1))); answerer = new BgpSessionStatusAnswerer( new BgpSessionStatusQuestion(null, null, null, "IBGP"), batfish); assertThat( (TableAnswerElement) answerer.answer(batfish.getSnapshot()), hasRows(emptyIterable())); }
@Override public AnswerElement answer(NetworkSnapshot snapshot) { BgpSessionStatusQuestion question = (BgpSessionStatusQuestion) _question; TableAnswerElement answer = new TableAnswerElement(createMetadata(question)); answer.postProcessAnswer(question, getRows(snapshot, question)); return answer; }
BgpSessionStatusAnswerer extends Answerer { @Override public AnswerElement answer(NetworkSnapshot snapshot) { BgpSessionStatusQuestion question = (BgpSessionStatusQuestion) _question; TableAnswerElement answer = new TableAnswerElement(createMetadata(question)); answer.postProcessAnswer(question, getRows(snapshot, question)); return answer; } }
BgpSessionStatusAnswerer extends Answerer { @Override public AnswerElement answer(NetworkSnapshot snapshot) { BgpSessionStatusQuestion question = (BgpSessionStatusQuestion) _question; TableAnswerElement answer = new TableAnswerElement(createMetadata(question)); answer.postProcessAnswer(question, getRows(snapshot, question)); return answer; } BgpSessionStatusAnswerer(Question question, IBatfish batfish); }
BgpSessionStatusAnswerer extends Answerer { @Override public AnswerElement answer(NetworkSnapshot snapshot) { BgpSessionStatusQuestion question = (BgpSessionStatusQuestion) _question; TableAnswerElement answer = new TableAnswerElement(createMetadata(question)); answer.postProcessAnswer(question, getRows(snapshot, question)); return answer; } BgpSessionStatusAnswerer(Question question, IBatfish batfish); @Override AnswerElement answer(NetworkSnapshot snapshot); }
BgpSessionStatusAnswerer extends Answerer { @Override public AnswerElement answer(NetworkSnapshot snapshot) { BgpSessionStatusQuestion question = (BgpSessionStatusQuestion) _question; TableAnswerElement answer = new TableAnswerElement(createMetadata(question)); answer.postProcessAnswer(question, getRows(snapshot, question)); return answer; } BgpSessionStatusAnswerer(Question question, IBatfish batfish); @Override AnswerElement answer(NetworkSnapshot snapshot);  }