use of org.batfish.datamodel.Interface in project batfish by batfish.
the class VirtualRouter method propagateRipInternalRoutes.
/**
* Process RIP routes from our neighbors.
*
* @param nodes Mapping of node names to Node instances
* @param topology The network topology
* @return True if the rib has changed as a result of route propagation
*/
boolean propagateRipInternalRoutes(Map<String, Node> nodes, Topology topology) {
boolean changed = false;
// No rip process, nothing to do
if (_vrf.getRipProcess() == null) {
return false;
}
String node = _c.getHostname();
int admin = RoutingProtocol.RIP.getDefaultAdministrativeCost(_c.getConfigurationFormat());
SortedSet<Edge> edges = topology.getNodeEdges().get(node);
if (edges == null) {
// there are no edges, so RIP won't produce anything
return false;
}
for (Edge edge : edges) {
// Do not accept routes from ourselves
if (!edge.getNode1().equals(node)) {
continue;
}
// Get interface
String connectingInterfaceName = edge.getInt1();
Interface connectingInterface = _vrf.getInterfaces().get(connectingInterfaceName);
if (connectingInterface == null) {
// wrong vrf, so skip
continue;
}
// Get the neighbor and its interface + VRF
String neighborName = edge.getNode2();
Node neighbor = nodes.get(neighborName);
String neighborInterfaceName = edge.getInt2();
Interface neighborInterface = neighbor._c.getInterfaces().get(neighborInterfaceName);
String neighborVrfName = neighborInterface.getVrfName();
VirtualRouter neighborVirtualRouter = nodes.get(neighborName)._virtualRouters.get(neighborVrfName);
if (connectingInterface.getRipEnabled() && !connectingInterface.getRipPassive() && neighborInterface.getRipEnabled() && !neighborInterface.getRipPassive()) {
/*
* We have a RIP neighbor relationship on this edge. So we should add all RIP routes
* from this neighbor into our RIP internal staging rib, adding the incremental cost
* (?), and using the neighborInterface's address as the next hop ip
*/
for (RipInternalRoute neighborRoute : neighborVirtualRouter._ripInternalRib.getRoutes()) {
long newCost = neighborRoute.getMetric() + RipProcess.DEFAULT_RIP_COST;
Ip nextHopIp = neighborInterface.getAddress().getIp();
RipInternalRoute newRoute = new RipInternalRoute(neighborRoute.getNetwork(), nextHopIp, admin, newCost);
if (_ripInternalStagingRib.mergeRoute(newRoute)) {
changed = true;
}
}
}
}
return changed;
}
use of org.batfish.datamodel.Interface in project batfish by batfish.
the class InterfacesSpecifierTest method matchesDesc.
@Test
public void matchesDesc() {
InterfacesSpecifier specifier = new InterfacesSpecifier("desc:secret.*");
Interface secretInterface = new Interface("Loopback0");
secretInterface.setDescription("secrets are never secrets for long");
Interface nonSecretInterface = new Interface("Ethetnet0/0");
nonSecretInterface.setDescription("this interface couldn't keep its secret");
assertThat(specifier.matches(secretInterface), equalTo(true));
assertThat(specifier.matches(nonSecretInterface), equalTo(false));
}
use of org.batfish.datamodel.Interface in project batfish by batfish.
the class Batfish method processNodeBlacklist.
private void processNodeBlacklist(Map<String, Configuration> configurations, ValidateEnvironmentAnswerElement veae) {
SortedSet<String> blacklistNodes = getNodeBlacklist();
for (String hostname : blacklistNodes) {
Configuration node = configurations.get(hostname);
if (node != null) {
for (Interface iface : node.getInterfaces().values()) {
iface.setActive(false);
iface.setBlacklisted(true);
}
} else {
veae.setValid(false);
veae.getUndefinedNodeBlacklistNodes().add(hostname);
}
}
}
use of org.batfish.datamodel.Interface in project batfish by batfish.
the class Batfish method disableUnusableVlanInterfaces.
private void disableUnusableVlanInterfaces(Map<String, Configuration> configurations) {
for (Configuration c : configurations.values()) {
Map<Integer, Interface> vlanInterfaces = new HashMap<>();
Map<Integer, Integer> vlanMemberCounts = new HashMap<>();
Set<Interface> nonVlanInterfaces = new HashSet<>();
Integer vlanNumber = null;
// vlanMemberCounts:
for (Interface iface : c.getInterfaces().values()) {
if ((iface.getInterfaceType() == InterfaceType.VLAN) && ((vlanNumber = CommonUtil.getInterfaceVlanNumber(iface.getName())) != null)) {
vlanInterfaces.put(vlanNumber, iface);
vlanMemberCounts.put(vlanNumber, 0);
} else {
nonVlanInterfaces.add(iface);
}
}
// Update vlanMemberCounts:
for (Interface iface : nonVlanInterfaces) {
List<SubRange> vlans = new ArrayList<>();
vlanNumber = iface.getAccessVlan();
if (vlanNumber == 0) {
// vlan trunked interface
vlans.addAll(iface.getAllowedVlans());
vlanNumber = iface.getNativeVlan();
}
vlans.add(new SubRange(vlanNumber, vlanNumber));
for (SubRange sr : vlans) {
for (int vlanId = sr.getStart(); vlanId <= sr.getEnd(); ++vlanId) {
vlanMemberCounts.compute(vlanId, (k, v) -> (v == null) ? 1 : (v + 1));
}
}
}
// Disable all "normal" vlan interfaces with zero member counts:
String hostname = c.getHostname();
SubRange normalVlanRange = c.getNormalVlanRange();
for (Map.Entry<Integer, Integer> entry : vlanMemberCounts.entrySet()) {
if (entry.getValue() == 0) {
vlanNumber = entry.getKey();
if ((vlanNumber >= normalVlanRange.getStart()) && (vlanNumber <= normalVlanRange.getEnd())) {
Interface iface = vlanInterfaces.get(vlanNumber);
if ((iface != null) && iface.getAutoState()) {
_logger.warnf("WARNING: Disabling unusable vlan interface because no switch port is assigned " + "to it: \"%s:%d\"\n", hostname, vlanNumber);
iface.setActive(false);
iface.setBlacklisted(true);
}
}
}
}
}
}
use of org.batfish.datamodel.Interface in project batfish by batfish.
the class Batfish method blacklistInterface.
/**
* Helper function to disable a blacklisted interface and update the given {@link
* ValidateEnvironmentAnswerElement} if the interface does not actually exist.
*/
private static void blacklistInterface(Map<String, Configuration> configurations, ValidateEnvironmentAnswerElement veae, NodeInterfacePair iface) {
String hostname = iface.getHostname();
String ifaceName = iface.getInterface();
@Nullable Configuration node = configurations.get(hostname);
if (node == null) {
veae.setValid(false);
veae.getUndefinedInterfaceBlacklistNodes().add(hostname);
return;
}
@Nullable Interface nodeIface = node.getInterfaces().get(ifaceName);
if (nodeIface == null) {
veae.setValid(false);
veae.getUndefinedInterfaceBlacklistInterfaces().computeIfAbsent(hostname, k -> new TreeSet<>()).add(ifaceName);
return;
}
nodeIface.setActive(false);
nodeIface.setBlacklisted(true);
}
Aggregations