use of org.batfish.datamodel.RipNeighbor in project batfish by batfish.
the class Batfish method initRemoteRipNeighbors.
@Override
public void initRemoteRipNeighbors(Map<String, Configuration> configurations, Map<Ip, Set<String>> ipOwners, Topology topology) {
for (Entry<String, Configuration> e : configurations.entrySet()) {
String hostname = e.getKey();
Configuration c = e.getValue();
for (Entry<String, Vrf> e2 : c.getVrfs().entrySet()) {
Vrf vrf = e2.getValue();
RipProcess proc = vrf.getRipProcess();
if (proc != null) {
proc.setRipNeighbors(new TreeMap<>());
String vrfName = e2.getKey();
for (String ifaceName : proc.getInterfaces()) {
Interface iface = vrf.getInterfaces().get("ifaceName");
SortedSet<Edge> ifaceEdges = topology.getInterfaceEdges().get(new NodeInterfacePair(hostname, ifaceName));
boolean hasNeighbor = false;
Ip localIp = iface.getAddress().getIp();
if (ifaceEdges != null) {
for (Edge edge : ifaceEdges) {
if (edge.getNode1().equals(hostname)) {
String remoteHostname = edge.getNode2();
String remoteIfaceName = edge.getInt2();
Configuration remoteNode = configurations.get(remoteHostname);
Interface remoteIface = remoteNode.getInterfaces().get(remoteIfaceName);
Vrf remoteVrf = remoteIface.getVrf();
String remoteVrfName = remoteVrf.getName();
RipProcess remoteProc = remoteVrf.getRipProcess();
if (remoteProc != null) {
if (remoteProc.getRipNeighbors() == null) {
remoteProc.setRipNeighbors(new TreeMap<>());
}
if (remoteProc.getInterfaces().contains(remoteIfaceName)) {
Ip remoteIp = remoteIface.getAddress().getIp();
Pair<Ip, Ip> localKey = new Pair<>(localIp, remoteIp);
RipNeighbor neighbor = proc.getRipNeighbors().get(localKey);
if (neighbor == null) {
hasNeighbor = true;
// initialize local neighbor
neighbor = new RipNeighbor(localKey);
neighbor.setVrf(vrfName);
neighbor.setOwner(c);
neighbor.setInterface(iface);
proc.getRipNeighbors().put(localKey, neighbor);
// initialize remote neighbor
Pair<Ip, Ip> remoteKey = new Pair<>(remoteIp, localIp);
RipNeighbor remoteNeighbor = new RipNeighbor(remoteKey);
remoteNeighbor.setVrf(remoteVrfName);
remoteNeighbor.setOwner(remoteNode);
remoteNeighbor.setInterface(remoteIface);
remoteProc.getRipNeighbors().put(remoteKey, remoteNeighbor);
// link neighbors
neighbor.setRemoteRipNeighbor(remoteNeighbor);
remoteNeighbor.setRemoteRipNeighbor(neighbor);
}
}
}
}
}
}
if (!hasNeighbor) {
Pair<Ip, Ip> key = new Pair<>(localIp, Ip.ZERO);
RipNeighbor neighbor = new RipNeighbor(key);
neighbor.setVrf(vrfName);
neighbor.setOwner(c);
neighbor.setInterface(iface);
proc.getRipNeighbors().put(key, neighbor);
}
}
}
}
}
}
Aggregations