use of org.batfish.datamodel.collections.NodeInterfacePair in project batfish by batfish.
the class Batfish method getInterfaceBlacklist.
@Nonnull
private SortedSet<NodeInterfacePair> getInterfaceBlacklist() {
SortedSet<NodeInterfacePair> blacklistInterfaces = Collections.emptySortedSet();
Path interfaceBlacklistPath = _testrigSettings.getEnvironmentSettings().getInterfaceBlacklistPath();
if (interfaceBlacklistPath != null && Files.exists(interfaceBlacklistPath)) {
blacklistInterfaces = parseInterfaceBlacklist(interfaceBlacklistPath);
}
return blacklistInterfaces;
}
use of org.batfish.datamodel.collections.NodeInterfacePair in project batfish by batfish.
the class Batfish method parseInterfaceBlacklist.
private SortedSet<NodeInterfacePair> parseInterfaceBlacklist(Path interfaceBlacklistPath) {
String interfaceBlacklistText = CommonUtil.readFile(interfaceBlacklistPath);
SortedSet<NodeInterfacePair> ifaces;
try {
ifaces = BatfishObjectMapper.mapper().readValue(interfaceBlacklistText, new TypeReference<SortedSet<NodeInterfacePair>>() {
});
} catch (IOException e) {
throw new BatfishException("Failed to parse interface blacklist", e);
}
return ifaces;
}
use of org.batfish.datamodel.collections.NodeInterfacePair 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);
}
}
}
}
}
}
use of org.batfish.datamodel.collections.NodeInterfacePair in project batfish by batfish.
the class CommonUtil method initRemoteOspfNeighbors.
public static void initRemoteOspfNeighbors(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();
OspfProcess proc = vrf.getOspfProcess();
if (proc != null) {
proc.setOspfNeighbors(new TreeMap<>());
String vrfName = e2.getKey();
for (Entry<Long, OspfArea> e3 : proc.getAreas().entrySet()) {
long areaNum = e3.getKey();
OspfArea area = e3.getValue();
for (String ifaceName : area.getInterfaces()) {
Interface iface = c.getInterfaces().get(ifaceName);
if (iface.getOspfPassive()) {
continue;
}
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);
if (remoteIface.getOspfPassive()) {
continue;
}
Vrf remoteVrf = remoteIface.getVrf();
String remoteVrfName = remoteVrf.getName();
OspfProcess remoteProc = remoteVrf.getOspfProcess();
if (remoteProc != null) {
if (remoteProc.getOspfNeighbors() == null) {
remoteProc.setOspfNeighbors(new TreeMap<>());
}
OspfArea remoteArea = remoteProc.getAreas().get(areaNum);
if (remoteArea != null && remoteArea.getInterfaces().contains(remoteIfaceName)) {
Ip remoteIp = remoteIface.getAddress().getIp();
IpLink localKey = new IpLink(localIp, remoteIp);
OspfNeighbor neighbor = proc.getOspfNeighbors().get(localKey);
if (neighbor == null) {
hasNeighbor = true;
// initialize local neighbor
neighbor = new OspfNeighbor(localKey);
neighbor.setArea(areaNum);
neighbor.setVrf(vrfName);
neighbor.setOwner(c);
neighbor.setInterface(iface);
proc.getOspfNeighbors().put(localKey, neighbor);
// initialize remote neighbor
IpLink remoteKey = new IpLink(remoteIp, localIp);
OspfNeighbor remoteNeighbor = new OspfNeighbor(remoteKey);
remoteNeighbor.setArea(areaNum);
remoteNeighbor.setVrf(remoteVrfName);
remoteNeighbor.setOwner(remoteNode);
remoteNeighbor.setInterface(remoteIface);
remoteProc.getOspfNeighbors().put(remoteKey, remoteNeighbor);
// link neighbors
neighbor.setRemoteOspfNeighbor(remoteNeighbor);
remoteNeighbor.setRemoteOspfNeighbor(neighbor);
}
}
}
}
}
}
if (!hasNeighbor) {
IpLink key = new IpLink(localIp, Ip.ZERO);
OspfNeighbor neighbor = new OspfNeighbor(key);
neighbor.setArea(areaNum);
neighbor.setVrf(vrfName);
neighbor.setOwner(c);
neighbor.setInterface(iface);
proc.getOspfNeighbors().put(key, neighbor);
}
}
}
}
}
}
}
Aggregations