private static SortedSet<VerboseOspfEdge> getOspfEdges(Map<String, Configuration> configs) { SortedSet<VerboseOspfEdge> ospfEdges = new TreeSet<>(); for (Configuration c : configs.values()) { String hostname = c.getHostname(); for (Vrf vrf : c.getVrfs().values()) { OspfProcess proc = vrf.getOspfProcess(); if (proc != null) { for (OspfNeighbor ospfNeighbor : proc.getOspfNeighbors().values()) { OspfNeighbor remoteOspfNeighbor = ospfNeighbor.getRemoteOspfNeighbor(); if (remoteOspfNeighbor != null) { Configuration remoteHost = remoteOspfNeighbor.getOwner(); String remoteHostname = remoteHost.getHostname(); Ip localIp = ospfNeighbor.getLocalIp(); Ip remoteIp = remoteOspfNeighbor.getLocalIp(); IpEdge edge = new IpEdge(hostname, localIp, remoteHostname, remoteIp); ospfEdges.add(new VerboseOspfEdge(ospfNeighbor, remoteOspfNeighbor, edge)); } } } } } return ospfEdges; }
private static SortedSet<VerboseRipEdge> getRipEdges(Map<String, Configuration> configs) { SortedSet<VerboseRipEdge> ripEdges = new TreeSet<>(); for (Configuration c : configs.values()) { String hostname = c.getHostname(); for (Vrf vrf : c.getVrfs().values()) { RipProcess proc = vrf.getRipProcess(); if (proc != null) { for (RipNeighbor ripNeighbor : proc.getRipNeighbors().values()) { RipNeighbor remoteRipNeighbor = ripNeighbor.getRemoteRipNeighbor(); if (remoteRipNeighbor != null) { Configuration remoteHost = remoteRipNeighbor.getOwner(); String remoteHostname = remoteHost.getHostname(); Ip localIp = ripNeighbor.getLocalIp(); Ip remoteIp = remoteRipNeighbor.getLocalIp(); IpEdge edge = new IpEdge(hostname, localIp, remoteHostname, remoteIp); ripEdges.add(new VerboseRipEdge(ripNeighbor, remoteRipNeighbor, edge)); } } } } } return ripEdges; } }
Ip localIp = bgpPeerConfig.getLocalIp(); Ip remoteIp = remoteBgpPeerConfig.getLocalIp(); IpEdge edge = new IpEdge(hostname, localIp, remoteHostname, remoteIp); return new VerboseBgpEdge( bgpPeerConfig, remoteBgpPeerConfig, bgpPeerConfigId, remoteBgpPeerConfigId, edge);
@Nonnull public IpEdge toIpEdge(NetworkConfigurations nc) { return new IpEdge( _node1.getHostname(), _node1.getInterface(nc).getAddress().getIp(), _node2.getHostname(), _node2.getInterface(nc).getAddress().getIp()); }
private static SortedSet<VerboseBgpEdge> getBgpEdges( Map<String, Configuration> configs, Map<Ip, Set<String>> ipOwners) { ValueGraph<BgpPeerConfigId, BgpSessionProperties> bgpTopology = BgpTopologyUtils.initBgpTopology(configs, ipOwners, false, false, null); SortedSet<VerboseBgpEdge> bgpEdges = new TreeSet<>(VERBOSE_BGP_EDGE_COMPARATOR); for (EndpointPair<BgpPeerConfigId> session : bgpTopology.edges()) { BgpPeerConfigId bgpPeerConfigId = session.source(); BgpPeerConfigId remoteBgpPeerConfigId = session.target(); NetworkConfigurations nc = NetworkConfigurations.of(configs); String hostname = bgpPeerConfigId.getHostname(); String remoteHostname = remoteBgpPeerConfigId.getHostname(); BgpPeerConfig bgpPeerConfig = nc.getBgpPeerConfig(bgpPeerConfigId); BgpPeerConfig remoteBgpPeerConfig = nc.getBgpPeerConfig(remoteBgpPeerConfigId); if (bgpPeerConfig != null && remoteBgpPeerConfig != null) { Ip localIp = bgpPeerConfig.getLocalIp(); Ip remoteIp = remoteBgpPeerConfig.getLocalIp(); IpEdge ipEdge = new IpEdge(hostname, localIp, remoteHostname, remoteIp); bgpEdges.add( new VerboseBgpEdge( bgpPeerConfig, remoteBgpPeerConfig, bgpPeerConfigId, remoteBgpPeerConfigId, ipEdge)); } } return bgpEdges; }
@Test public void testCompareTo() { Ip ip1 = Ip.parse("1.1.1.1"); Ip ip2 = Ip.parse("2.2.2.2"); Pair<Ip, Ip> ipPair1 = new Pair<>(ip1, ip1); Pair<Ip, Ip> ipPair2 = new Pair<>(ip2, ip2); String node1 = "node1"; String node2 = "node2"; IpEdge ipEdge1 = new IpEdge(node1, ip1, node1, ip1); IpEdge ipEdge2 = new IpEdge(node2, ip2, node2, ip2); RipNeighbor neighbor1 = new RipNeighbor(ipPair1); RipNeighbor neighbor2 = new RipNeighbor(ipPair2); VerboseRipEdge ripEdge1 = new VerboseRipEdge(neighbor1, neighbor1, ipEdge1); VerboseRipEdge ripEdge1Copy = new VerboseRipEdge(neighbor1, neighbor1, ipEdge1); VerboseRipEdge ripEdge2 = new VerboseRipEdge(neighbor2, neighbor2, ipEdge2); assertThat(ripEdge1.compareTo(ripEdge1Copy), is(0)); assertThat(ripEdge1.compareTo(ripEdge2), lessThan(0)); assertThat(ripEdge2.compareTo(ripEdge1), greaterThan(0)); } }
Ip localIp = ospfNeighbor.getLocalIp(); Ip remoteIp = remoteOspfNeighbor.getLocalIp(); IpEdge edge = new IpEdge(hostname, localIp, remoteHostname, remoteIp); vedges.add(new VerboseOspfEdge(ospfNeighbor, remoteOspfNeighbor, edge)); Ip localIp = ripNeighbor.getLocalIp(); Ip remoteIp = remoteRipNeighbor.getLocalIp(); IpEdge edge = new IpEdge(hostname, localIp, remoteHostname, remoteIp); vedges.add(new VerboseRipEdge(ripNeighbor, remoteRipNeighbor, edge));