@Test public void testGetBgpEdges() { BgpProcess bgp1 = new BgpProcess(Ip.parse("1.1.1.1"), ConfigurationFormat.CISCO_IOS); BgpProcess bgp2 = new BgpProcess(Ip.parse("2.2.2.2"), ConfigurationFormat.CISCO_IOS); Ip ip1 = Ip.parse("1.1.1.1"); Ip ip2 = Ip.parse("2.2.2.2"); BgpActivePeerConfig activePeer1 = BgpActivePeerConfig.builder() .setLocalIp(ip1) .setLocalAs(1L) .setIpv4UnicastAddressFamily(Ipv4UnicastAddressFamily.builder().build()) .build(); bgp1.getActiveNeighbors().put(ip2.toPrefix(), activePeer1); BgpPeerConfigId activeId1 = new BgpPeerConfigId("host1", "vrf1", ip2.toPrefix(), false); BgpActivePeerConfig activePeer2 = BgpActivePeerConfig.builder() .setLocalIp(ip2) .setLocalAs(2L) .setIpv4UnicastAddressFamily(Ipv4UnicastAddressFamily.builder().build()) .build(); bgp2.getActiveNeighbors().put(ip1.toPrefix(), activePeer2); BgpPeerConfigId activeId2 = new BgpPeerConfigId("host2", "vrf2", ip1.toPrefix(), false); String iface1 = "iface1"; String iface2 = "iface2"; BgpUnnumberedPeerConfig unnumPeer1 = BgpUnnumberedPeerConfig.builder() .setPeerInterface(iface1) .setLocalAs(1L) .setLocalIp(Ip.parse("169.254.0.1")) .setIpv4UnicastAddressFamily(Ipv4UnicastAddressFamily.builder().build()) .build(); bgp1.getInterfaceNeighbors().put(iface1, unnumPeer1); BgpPeerConfigId unnumId1 = new BgpPeerConfigId("host1", "vrf1", iface1); BgpUnnumberedPeerConfig unnumPeer2 = BgpUnnumberedPeerConfig.builder() .setPeerInterface(iface2) .setLocalAs(2L) .setLocalIp(Ip.parse("169.254.0.1")) .setIpv4UnicastAddressFamily(Ipv4UnicastAddressFamily.builder().build()) .build(); bgp2.getInterfaceNeighbors().put(iface2, unnumPeer2); BgpPeerConfigId unnumId2 = new BgpPeerConfigId("host2", "vrf2", iface2); Vrf vrf1 = new Vrf("vrf1"); vrf1.setBgpProcess(bgp1); Vrf vrf2 = new Vrf("vrf2"); vrf2.setBgpProcess(bgp2); _host1.setVrfs(ImmutableSortedMap.of("vrf1", vrf1)); _host2.setVrfs(ImmutableSortedMap.of("vrf2", vrf2)); MutableValueGraph<BgpPeerConfigId, BgpSessionProperties> bgpTopology = ValueGraphBuilder.directed().allowsSelfLoops(false).build(); bgpTopology.putEdgeValue( activeId1, activeId2, BgpSessionProperties.from(activePeer1, activePeer2, false)); bgpTopology.putEdgeValue( unnumId1, unnumId2, BgpSessionProperties.from(unnumPeer1, unnumPeer2, false)); Multiset<Row> rows = getBgpEdges( _configurations, _includeNodes, _includeRemoteNodes, new BgpTopology(bgpTopology)); Row expectedActiveRow = Row.builder() .put(COL_NODE, new Node("host1")) .put(COL_IP, ip1) .put(COL_INTERFACE, null) .put(COL_AS_NUMBER, 1L) .put(COL_REMOTE_NODE, new Node("host2")) .put(COL_REMOTE_IP, ip2) .put(COL_REMOTE_INTERFACE, null) .put(COL_REMOTE_AS_NUMBER, 2L) .build(); Row expectedUnnumRow = Row.builder() .put(COL_NODE, new Node("host1")) .put(COL_IP, null) .put(COL_INTERFACE, iface1) .put(COL_AS_NUMBER, 1L) .put(COL_REMOTE_NODE, new Node("host2")) .put(COL_REMOTE_IP, null) .put(COL_REMOTE_INTERFACE, iface2) .put(COL_REMOTE_AS_NUMBER, 2L) .build(); assertThat(rows, containsInAnyOrder(expectedActiveRow, expectedUnnumRow)); }
@VisibleForTesting static Multiset<Row> getBgpEdges( Map<String, Configuration> configurations, Set<String> includeNodes, Set<String> includeRemoteNodes, BgpTopology bgpTopology) { Multiset<Row> rows = HashMultiset.create(); Map<String, ColumnMetadata> columnMap = getTableMetadata(EdgeType.BGP).toColumnMap(); for (EndpointPair<BgpPeerConfigId> session : bgpTopology.getGraph().edges()) { BgpPeerConfigId bgpPeerConfigId = session.source(); BgpPeerConfigId remoteBgpPeerConfigId = session.target(); NetworkConfigurations nc = NetworkConfigurations.of(configurations); BgpPeerConfig bgpPeerConfig = nc.getBgpPeerConfig(bgpPeerConfigId); BgpPeerConfig remoteBgpPeerConfig = nc.getBgpPeerConfig(remoteBgpPeerConfigId); if (bgpPeerConfig == null || remoteBgpPeerConfig == null) { continue; } String hostname = bgpPeerConfigId.getHostname(); String remoteHostname = remoteBgpPeerConfigId.getHostname(); if (includeNodes.contains(hostname) && includeRemoteNodes.contains(remoteHostname)) { BgpSessionProperties sessionProperties = bgpTopology.getGraph().edgeValue(bgpPeerConfigId, remoteBgpPeerConfigId).orElse(null); assert sessionProperties != null; boolean unnumbered = bgpPeerConfigId.getType() == BgpPeerConfigType.UNNUMBERED; rows.add( Row.builder(columnMap) .put(COL_NODE, new Node(hostname)) .put(COL_IP, unnumbered ? null : sessionProperties.getTailIp()) .put(COL_INTERFACE, bgpPeerConfigId.getPeerInterface()) .put(COL_AS_NUMBER, sessionProperties.getTailAs()) .put(COL_REMOTE_NODE, new Node(remoteHostname)) .put(COL_REMOTE_IP, unnumbered ? null : sessionProperties.getHeadIp()) .put(COL_REMOTE_INTERFACE, remoteBgpPeerConfigId.getPeerInterface()) .put(COL_REMOTE_AS_NUMBER, sessionProperties.getHeadAs()) .build()); } } return rows; }
EdgesAnswerer extends Answerer { @VisibleForTesting static Multiset<Row> getBgpEdges( Map<String, Configuration> configurations, Set<String> includeNodes, Set<String> includeRemoteNodes, BgpTopology bgpTopology) { Multiset<Row> rows = HashMultiset.create(); Map<String, ColumnMetadata> columnMap = getTableMetadata(EdgeType.BGP).toColumnMap(); for (EndpointPair<BgpPeerConfigId> session : bgpTopology.getGraph().edges()) { BgpPeerConfigId bgpPeerConfigId = session.source(); BgpPeerConfigId remoteBgpPeerConfigId = session.target(); NetworkConfigurations nc = NetworkConfigurations.of(configurations); BgpPeerConfig bgpPeerConfig = nc.getBgpPeerConfig(bgpPeerConfigId); BgpPeerConfig remoteBgpPeerConfig = nc.getBgpPeerConfig(remoteBgpPeerConfigId); if (bgpPeerConfig == null || remoteBgpPeerConfig == null) { continue; } String hostname = bgpPeerConfigId.getHostname(); String remoteHostname = remoteBgpPeerConfigId.getHostname(); if (includeNodes.contains(hostname) && includeRemoteNodes.contains(remoteHostname)) { BgpSessionProperties sessionProperties = bgpTopology.getGraph().edgeValue(bgpPeerConfigId, remoteBgpPeerConfigId).orElse(null); assert sessionProperties != null; boolean unnumbered = bgpPeerConfigId.getType() == BgpPeerConfigType.UNNUMBERED; rows.add( Row.builder(columnMap) .put(COL_NODE, new Node(hostname)) .put(COL_IP, unnumbered ? null : sessionProperties.getTailIp()) .put(COL_INTERFACE, bgpPeerConfigId.getPeerInterface()) .put(COL_AS_NUMBER, sessionProperties.getTailAs()) .put(COL_REMOTE_NODE, new Node(remoteHostname)) .put(COL_REMOTE_IP, unnumbered ? null : sessionProperties.getHeadIp()) .put(COL_REMOTE_INTERFACE, remoteBgpPeerConfigId.getPeerInterface()) .put(COL_REMOTE_AS_NUMBER, sessionProperties.getHeadAs()) .build()); } } return rows; } }
EdgesAnswerer extends Answerer { @VisibleForTesting static Multiset<Row> getBgpEdges( Map<String, Configuration> configurations, Set<String> includeNodes, Set<String> includeRemoteNodes, BgpTopology bgpTopology) { Multiset<Row> rows = HashMultiset.create(); Map<String, ColumnMetadata> columnMap = getTableMetadata(EdgeType.BGP).toColumnMap(); for (EndpointPair<BgpPeerConfigId> session : bgpTopology.getGraph().edges()) { BgpPeerConfigId bgpPeerConfigId = session.source(); BgpPeerConfigId remoteBgpPeerConfigId = session.target(); NetworkConfigurations nc = NetworkConfigurations.of(configurations); BgpPeerConfig bgpPeerConfig = nc.getBgpPeerConfig(bgpPeerConfigId); BgpPeerConfig remoteBgpPeerConfig = nc.getBgpPeerConfig(remoteBgpPeerConfigId); if (bgpPeerConfig == null || remoteBgpPeerConfig == null) { continue; } String hostname = bgpPeerConfigId.getHostname(); String remoteHostname = remoteBgpPeerConfigId.getHostname(); if (includeNodes.contains(hostname) && includeRemoteNodes.contains(remoteHostname)) { BgpSessionProperties sessionProperties = bgpTopology.getGraph().edgeValue(bgpPeerConfigId, remoteBgpPeerConfigId).orElse(null); assert sessionProperties != null; boolean unnumbered = bgpPeerConfigId.getType() == BgpPeerConfigType.UNNUMBERED; rows.add( Row.builder(columnMap) .put(COL_NODE, new Node(hostname)) .put(COL_IP, unnumbered ? null : sessionProperties.getTailIp()) .put(COL_INTERFACE, bgpPeerConfigId.getPeerInterface()) .put(COL_AS_NUMBER, sessionProperties.getTailAs()) .put(COL_REMOTE_NODE, new Node(remoteHostname)) .put(COL_REMOTE_IP, unnumbered ? null : sessionProperties.getHeadIp()) .put(COL_REMOTE_INTERFACE, remoteBgpPeerConfigId.getPeerInterface()) .put(COL_REMOTE_AS_NUMBER, sessionProperties.getHeadAs()) .build()); } } return rows; } EdgesAnswerer(Question question, IBatfish batfish); }
EdgesAnswerer extends Answerer { @VisibleForTesting static Multiset<Row> getBgpEdges( Map<String, Configuration> configurations, Set<String> includeNodes, Set<String> includeRemoteNodes, BgpTopology bgpTopology) { Multiset<Row> rows = HashMultiset.create(); Map<String, ColumnMetadata> columnMap = getTableMetadata(EdgeType.BGP).toColumnMap(); for (EndpointPair<BgpPeerConfigId> session : bgpTopology.getGraph().edges()) { BgpPeerConfigId bgpPeerConfigId = session.source(); BgpPeerConfigId remoteBgpPeerConfigId = session.target(); NetworkConfigurations nc = NetworkConfigurations.of(configurations); BgpPeerConfig bgpPeerConfig = nc.getBgpPeerConfig(bgpPeerConfigId); BgpPeerConfig remoteBgpPeerConfig = nc.getBgpPeerConfig(remoteBgpPeerConfigId); if (bgpPeerConfig == null || remoteBgpPeerConfig == null) { continue; } String hostname = bgpPeerConfigId.getHostname(); String remoteHostname = remoteBgpPeerConfigId.getHostname(); if (includeNodes.contains(hostname) && includeRemoteNodes.contains(remoteHostname)) { BgpSessionProperties sessionProperties = bgpTopology.getGraph().edgeValue(bgpPeerConfigId, remoteBgpPeerConfigId).orElse(null); assert sessionProperties != null; boolean unnumbered = bgpPeerConfigId.getType() == BgpPeerConfigType.UNNUMBERED; rows.add( Row.builder(columnMap) .put(COL_NODE, new Node(hostname)) .put(COL_IP, unnumbered ? null : sessionProperties.getTailIp()) .put(COL_INTERFACE, bgpPeerConfigId.getPeerInterface()) .put(COL_AS_NUMBER, sessionProperties.getTailAs()) .put(COL_REMOTE_NODE, new Node(remoteHostname)) .put(COL_REMOTE_IP, unnumbered ? null : sessionProperties.getHeadIp()) .put(COL_REMOTE_INTERFACE, remoteBgpPeerConfigId.getPeerInterface()) .put(COL_REMOTE_AS_NUMBER, sessionProperties.getHeadAs()) .build()); } } return rows; } EdgesAnswerer(Question question, IBatfish batfish); @Override AnswerElement answer(NetworkSnapshot snapshot); }
EdgesAnswerer extends Answerer { @VisibleForTesting static Multiset<Row> getBgpEdges( Map<String, Configuration> configurations, Set<String> includeNodes, Set<String> includeRemoteNodes, BgpTopology bgpTopology) { Multiset<Row> rows = HashMultiset.create(); Map<String, ColumnMetadata> columnMap = getTableMetadata(EdgeType.BGP).toColumnMap(); for (EndpointPair<BgpPeerConfigId> session : bgpTopology.getGraph().edges()) { BgpPeerConfigId bgpPeerConfigId = session.source(); BgpPeerConfigId remoteBgpPeerConfigId = session.target(); NetworkConfigurations nc = NetworkConfigurations.of(configurations); BgpPeerConfig bgpPeerConfig = nc.getBgpPeerConfig(bgpPeerConfigId); BgpPeerConfig remoteBgpPeerConfig = nc.getBgpPeerConfig(remoteBgpPeerConfigId); if (bgpPeerConfig == null || remoteBgpPeerConfig == null) { continue; } String hostname = bgpPeerConfigId.getHostname(); String remoteHostname = remoteBgpPeerConfigId.getHostname(); if (includeNodes.contains(hostname) && includeRemoteNodes.contains(remoteHostname)) { BgpSessionProperties sessionProperties = bgpTopology.getGraph().edgeValue(bgpPeerConfigId, remoteBgpPeerConfigId).orElse(null); assert sessionProperties != null; boolean unnumbered = bgpPeerConfigId.getType() == BgpPeerConfigType.UNNUMBERED; rows.add( Row.builder(columnMap) .put(COL_NODE, new Node(hostname)) .put(COL_IP, unnumbered ? null : sessionProperties.getTailIp()) .put(COL_INTERFACE, bgpPeerConfigId.getPeerInterface()) .put(COL_AS_NUMBER, sessionProperties.getTailAs()) .put(COL_REMOTE_NODE, new Node(remoteHostname)) .put(COL_REMOTE_IP, unnumbered ? null : sessionProperties.getHeadIp()) .put(COL_REMOTE_INTERFACE, remoteBgpPeerConfigId.getPeerInterface()) .put(COL_REMOTE_AS_NUMBER, sessionProperties.getHeadAs()) .build()); } } return rows; } EdgesAnswerer(Question question, IBatfish batfish); @Override AnswerElement answer(NetworkSnapshot snapshot);  }