private boolean propagateOspfInterAreaRouteFromIntraAreaRoute( Configuration neighbor, OspfProcess neighborProc, OspfIntraAreaRoute neighborRoute, long incrementalCost, Interface neighborInterface, int adminCost, long linkAreaNum) { return OspfProtocolHelper.isOspfInterAreaFromIntraAreaPropagationAllowed( linkAreaNum, neighbor, neighborProc, neighborRoute, neighborInterface.getOspfArea()) && stageOspfInterAreaRoute( neighborRoute, neighborInterface.getVrf().getOspfProcess().getMaxMetricSummaryNetworks(), neighborInterface.getAddress().getIp(), incrementalCost, adminCost, linkAreaNum); }
@Override public Interface build() { String name = _name != null ? _name : generateName(); Interface iface = new Interface(name, _owner); ImmutableSet.Builder<InterfaceAddress> allAddresses = ImmutableSet.builder(); iface.setActive(_active); if (_address != null) { iface.setAddress(_address); allAddresses.add(_address); iface.setAdditionalArpIps(_additionalArpIps); iface.setAllAddresses(allAddresses.addAll(_secondaryAddresses).build()); iface.setBandwidth(_bandwidth); iface.setBlacklisted(_blacklisted); iface.setDeclaredNames(_declaredNames); iface.setDependencies(_dependencies); iface.setEigrp(_eigrp); iface.setEncapsulationVlan(_encapsulationVlan); iface.setHsrpGroups(_hsrpGroups); iface.setHsrpVersion(_hsrpVersion); iface.setFirewallSessionInterfaceInfo(_firewallSessionInterfaceInfo); iface.setIncomingFilter(_incomingFilter); iface.setIncomingTransformation(_incomingTransformation); iface.setIsis(_isis); iface.setOspfArea(_ospfArea); if (_ospfArea != null) { _ospfArea.addInterface(name); iface.setOspfAreaName(_ospfArea.getAreaNumber()); iface.setOspfCost(_ospfCost);
/** Returns true iff the given trunk interface allows its own native vlan. */ private static boolean trunkWithNativeVlanAllowed(Interface i) { return i.getSwitchportMode() == SwitchportMode.TRUNK && i.getNativeVlan() != null && i.getAllowedVlans().contains(i.getNativeVlan()); }
public boolean isInterfaceActive(Protocol proto, Interface iface) { if (proto.isOspf()) { return iface.getActive() && iface.getOspfEnabled(); } return iface.getActive(); }
private Interface createIbgpInterface(BgpActivePeerConfig n, String peer) { Interface iface = new Interface("iBGP-" + peer); iface.setActive(true); // TODO is this valid. iface.setAddress(new InterfaceAddress(n.getPeerAddress(), Prefix.MAX_PREFIX_LENGTH)); iface.setBandwidth(0.); return iface; }
private org.batfish.datamodel.Interface toInterface(Interface iface) { String name = iface.getName(); org.batfish.datamodel.Interface newIface = new org.batfish.datamodel.Interface(name, _c); newIface.setDeclaredNames(ImmutableSortedSet.of(name)); newIface.setDescription(iface.getDescription()); Integer mtu = iface.getMtu(); if (mtu != null) { newIface.setMtu(mtu); newIface.setVrrpGroups(iface.getVrrpGroups()); newIface.setVrf(_c.getVrfs().get(iface.getRoutingInstance())); newIface.setAdditionalArpIps(iface.getAdditionalArpIps()); Zone zone = _masterLogicalSystem.getInterfaceZones().get(iface.getName()); if (zone != null) { IpAccessList zoneInboundInterfaceFilterList = _c.getIpAccessLists().get(zoneInboundInterfaceFilterName); newIface.setInboundFilter(zoneInboundInterfaceFilterList); } else { String zoneInboundFilterName = zoneInboundFilter.getName(); IpAccessList zoneInboundFilterList = _c.getIpAccessLists().get(zoneInboundFilterName); newIface.setInboundFilter(zoneInboundFilterList); newIface.setFirewallSessionInterfaceInfo( new FirewallSessionInterfaceInfo( zone.getInterfaces().stream().map(Interface::getName).collect(Collectors.toList()), RoutingPolicy routingPolicy = _c.getRoutingPolicies().get(inAclName); if (routingPolicy != null) {
if ((iface.getInterfaceType() == InterfaceType.VLAN) && ((vlanNumber = CommonUtil.getInterfaceVlanNumber(iface.getName())) != null)) { vlanInterfaces.put(vlanNumber, iface); vlanMemberCounts.put(vlanNumber, 0); if (iface.getSwitchportMode() == SwitchportMode.TRUNK) { // vlan trunked interface IntegerSpace allowed = iface.getAllowedVlans(); if (!allowed.isEmpty()) { vlanNumber = iface.getNativeVlan(); if (vlanNumber != null) { vlans.including(vlanNumber); } else if (iface.getSwitchportMode() == SwitchportMode.ACCESS) { // access mode ACCESS vlanNumber = iface.getAccessVlan(); if (vlanNumber != null) { vlans.including(vlanNumber); } else if (iface.getSwitchportMode() != SwitchportMode.NONE) { _logger.warnf( "WARNING: Unsupported switch port mode %s, assuming no VLANs allowed: \"%s:%s\"\n", iface.getSwitchportMode(), hostname, iface.getName()); && (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",
@VisibleForTesting static void tryAddInterfaceToVlans( SpecifierContext ctxt, InterfaceSpecifier interfacesSpecifier, boolean excludeShutInterfaces, IntegerSpace vlans, Map<Integer, ImmutableSet.Builder<NodeInterfacePair>> switchedVlanInterfaces, String node, Interface iface) { if (!interfacesSpecifier.resolve(ImmutableSet.of(node), ctxt).contains(iface) || (excludeShutInterfaces && !iface.getActive()) || (iface.getInterfaceType() != InterfaceType.VLAN && !Boolean.TRUE.equals(iface.getSwitchport()))) { return; } if (iface.getInterfaceType() == InterfaceType.VLAN) { // Add VLAN associated with IRB-type interface tryAddInterfaceToVlan(switchedVlanInterfaces, node, iface, iface.getVlan(), vlans); } else if (iface.getSwitchportMode() == SwitchportMode.ACCESS) { // Add access VLAN when in ACCESS mode tryAddInterfaceToVlan(switchedVlanInterfaces, node, iface, iface.getAccessVlan(), vlans); } else if (iface.getSwitchportMode() == SwitchportMode.TRUNK) { // Add allowed VLANs when in TRUNK mode iface.getAllowedVlans().stream() .forEach( allowedVlan -> tryAddInterfaceToVlan(switchedVlanInterfaces, node, iface, allowedVlan, vlans)); } }
.forEach( i -> { if (i.getSwitchportMode() == SwitchportMode.TRUNK) { i.getAllowedVlans().stream() .forEach( vlan -> switchportsByVlanBuilder .computeIfAbsent(vlan, n -> ImmutableList.builder()) .add(i.getName())); } else if (i.getSwitchportMode() == SwitchportMode.ACCESS && i.getAccessVlan() != null) { switchportsByVlanBuilder .computeIfAbsent(i.getAccessVlan(), n -> ImmutableList.builder()) .add(i.getName()); }); vrf.getInterfaces().values().stream() .filter(i -> i.getInterfaceType() == InterfaceType.VLAN) .forEach( irbInterface -> { String irbName = irbInterface.getName(); int vlanId = irbInterface.getVlan(); switchportsByVlan .getOrDefault(vlanId, ImmutableList.of())
private org.batfish.datamodel.Interface toInterface(Interface iface) { String name = iface.getName(); org.batfish.datamodel.Interface newIface = new org.batfish.datamodel.Interface(name, _c); newIface.setDeclaredNames(ImmutableSortedSet.of(name)); newIface.setActive(true); // TODO: may have to change newIface.setBandwidth(iface.getBandwidth()); newIface.setDescription(iface.getDescription()); InterfaceAddress address = iface.getAddress(); if (address != null) { newIface.setAddress(iface.getAddress()); } newIface.getAllAddresses().addAll(iface.getAllAddresses()); for (InterfaceAddress p : newIface.getAllAddresses()) { _ipToInterfaceMap.put(p.getIp(), newIface); } return newIface; }
for (Configuration c : configurations.values()) { for (Interface i : c.getAllInterfaces().values()) { if (i.getActive() && i.getAddress() != null) { for (InterfaceAddress address : i.getAllAddresses()) { Set<String> currentIpOwners = ipOwners.computeIfAbsent(address.getIp(), k -> new HashSet<>()); ospfNeighborSummary); } else if (ospfNeighbor.getRemoteOspfNeighbor() == null) { if (!ospfNeighbor.getIface().getOspfPassive()) { int linkCost = ospfNeighbor.getIface().getOspfCost(); int remoteLinkCost = remoteOspfNeighbor.getIface().getOspfCost(); if (linkCost != remoteLinkCost) { answerElement.add(
String name = iface.getName(); org.batfish.datamodel.Interface newIface = new org.batfish.datamodel.Interface(name, _c, InterfaceType.PHYSICAL); Integer mtu = iface.getMtu(); if (mtu != null) { newIface.setMtu(mtu); newIface.setAddress(iface.getAddress()); newIface.setAllAddresses(iface.getAllAddresses()); newIface.setActive(iface.getActive()); newIface.setDescription(iface.getComment()); newIface.setZoneName(zone.getName()); newIface.setOutgoingFilter( IpAccessList.builder() .setOwner(_c) } else { newIface.setOutgoingFilter( IpAccessList.builder() .setOwner(_c)
OspfArea localArea = localInterface.getOspfArea(); if (!localInterface.getOspfEnabled() || localInterface.getOspfPassive() || localArea == null) { InterfaceAddress localPrimary = localInterface.getAddress(); InterfaceAddress neighborPrimary = neighborInterface.getAddress(); if (!localPrimary.getPrefix().containsIp(neighborPrimary.getIp()) || !neighborPrimary.getPrefix().containsIp(localPrimary.getIp()) OspfArea neighborArea = neighborInterface.getOspfArea(); if (!neighborInterface.getOspfEnabled() || neighborInterface.getOspfPassive() || neighborArea == null) { OspfNode localNode = new OspfNode(node, localInterface.getName(), localPrimary.getIp()); OspfNode neighborNode = new OspfNode( neighbor.getConfiguration().getHostname(), neighborInterface.getName(), neighborPrimary.getIp()); neighbors.add(new OspfEdge(localNode, neighborNode));
@VisibleForTesting static int computeInterfaceCost(Double referenceBandwidth, Interface i) { Integer ospfCost = i.getOspfCost(); if (ospfCost != null) { return ospfCost; } String interfaceName = i.getName(); if (interfaceName.startsWith("Vlan")) { // Special handling for VLAN interfaces // TODO: fix for non-cisco return DEFAULT_CISCO_VLAN_OSPF_COST; } else { // Regular physical interface cost computation checkState( i.getBandwidth() != null, "Interface %s on %s is missing bandwidth, cannot compute OSPF cost", interfaceName, i.getOwner().getHostname()); return Math.max((int) (referenceBandwidth / i.getBandwidth()), 1); } }
/** * Convert a non-unit interface to the VI {@link org.batfish.datamodel.Interface}. * * <p>Note that bulk of the configuration is stored at the logical interface level, see {@link * #toInterface(Interface)} for those conversions. Here we convert aggregation and bandwidth * settings; track VRF membership. */ private org.batfish.datamodel.Interface toInterfaceNonUnit(Interface iface) { String name = iface.getName(); org.batfish.datamodel.Interface newIface = new org.batfish.datamodel.Interface(name, _c); newIface.setDeclaredNames(ImmutableSortedSet.of(name)); newIface.setDescription(iface.getDescription()); // 802.3ad link aggregation if (iface.get8023adInterface() != null) { newIface.setChannelGroup(iface.get8023adInterface()); } // Redundant ethernet if (iface.getRedundantParentInterface() != null) { newIface.setChannelGroup(iface.getRedundantParentInterface()); } newIface.setBandwidth(iface.getBandwidth()); newIface.setVrf(_c.getVrfs().get(iface.getRoutingInstance())); return newIface; }
/** * Initialize the connected RIB -- a RIB containing connected routes (i.e., direct connections to * neighbors). */ @VisibleForTesting void initConnectedRib() { // Look at all connected interfaces for (Interface i : _vrf.getInterfaces().values()) { if (i.getActive()) { // Make sure the interface is active // Create a route for each interface prefix for (InterfaceAddress ifaceAddress : i.getAllAddresses()) { Prefix prefix = ifaceAddress.getPrefix(); ConnectedRoute cr = new ConnectedRoute(prefix, i.getName()); _connectedRib.mergeRoute(cr); } } } }
for (String ifaceName : area.getInterfaces()) { Interface iface = _c.getAllInterfaces().get(ifaceName); if (iface.getActive()) { Set<Prefix> allNetworkPrefixes = iface.getAllAddresses().stream() .map(InterfaceAddress::getPrefix) .collect(Collectors.toSet()); int interfaceOspfCost = iface.getOspfCost(); for (Prefix prefix : allNetworkPrefixes) { long cost = interfaceOspfCost; boolean stubNetwork = iface.getOspfPassive() || iface.getOspfPointToPoint(); if (stubNetwork) { if (proc.getMaxMetricStubNetworks() != null) {
iface -> { iface .getAllAddresses() .forEach( address -> { Row.builder() .put(COL_NODE, new Node(hostname)) .put(COL_VRFNAME, iface.getVrfName()) .put(COL_INTERFACE_NAME, iface.getName()) .put(COL_IP, address.getIp()) .put(COL_MASK, address.getNetworkBits()) .put(COL_ACTIVE, iface.getActive()) .build());
String buildRoute(Prefix pfx, Protocol proto, GraphEdge graphEdge) { String type; String nextHopIP; String nextHopInt; if (proto.isConnected()) { type = "ConnectedRoute"; nextHopIP = "AUTO/NONE(-1l)"; nextHopInt = graphEdge.getStart().getName(); } else { type = StringUtils.capitalize(proto.name().toLowerCase()) + "Route"; nextHopIP = graphEdge.getStart().getAddress().getIp().toString(); nextHopInt = "dynamic"; } return String.format("%s<%s,nhip:%s,nhint:%s>", type, pfx, nextHopIP, nextHopInt); }