@Override protected SwitchportMode featureValueOf(Interface actual) { return actual.getSwitchportMode(); } }
/** 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()); }
private static void tryComputeLayer2EdgesForLayer1ChildEdge( Layer1Edge layer1MappedEdge, Map<String, Configuration> configurations, Builder<Layer2Edge> edges) { Layer1Node node1 = layer1MappedEdge.getNode1(); Layer1Node node2 = layer1MappedEdge.getNode2(); Interface i1 = getInterface(node1, configurations); Interface i2 = getInterface(node2, configurations); // Exit early if either interface is missing if (i1 == null || i2 == null) { return; } if (i1.getSwitchportMode() == SwitchportMode.TRUNK || i2.getSwitchportMode() == SwitchportMode.TRUNK) { addLayer2TrunkEdges(i1, i2, edges, node1, node2); } else if (i1.getEncapsulationVlan() != null || i2.getEncapsulationVlan() != null) { // Both interfaces are tagged Layer3 interfaces tryAddLayer2TaggedNonTrunkEdge(i1, i2, edges, node1, node2); } else { Integer node1VlanId = i1.getSwitchportMode() == SwitchportMode.ACCESS ? i1.getAccessVlan() : null; Integer node2VlanId = i2.getSwitchportMode() == SwitchportMode.ACCESS ? i2.getAccessVlan() : null; edges.add(new Layer2Edge(node1, node1VlanId, node2, node2VlanId, null)); } }
.forEach( i -> { if (i.getSwitchportMode() == SwitchportMode.TRUNK) { i.getAllowedVlans().stream() .forEach( .computeIfAbsent(vlan, n -> ImmutableList.builder()) .add(i.getName())); } else if (i.getSwitchportMode() == SwitchportMode.ACCESS && i.getAccessVlan() != null) { switchportsByVlanBuilder
@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)); } }
if (iface.getSwitchportMode() == SwitchportMode.TRUNK) { // vlan trunked interface IntegerSpace allowed = iface.getAllowedVlans(); if (!allowed.isEmpty()) { vlans.including(vlanNumber); } else if (iface.getSwitchportMode() == SwitchportMode.ACCESS) { // access mode ACCESS vlanNumber = iface.getAccessVlan(); if (vlanNumber != null) { } 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());
Integer i1Tag = i1.getEncapsulationVlan(); Integer i2Tag = i2.getEncapsulationVlan(); if (i1.getSwitchportMode() == SwitchportMode.TRUNK && i2.getSwitchportMode() == SwitchportMode.TRUNK) { i2.getSwitchportMode() == SwitchportMode.ACCESS ? i2.getAccessVlan() : null; edges.add(new Layer2Edge(node1, i1.getNativeVlan(), node2, node2VlanId, null)); } else if (trunkWithNativeVlanAllowed(i2)) { i1.getSwitchportMode() == SwitchportMode.ACCESS ? i1.getAccessVlan() : null; edges.add(new Layer2Edge(node1, node1VlanId, node2, i2.getNativeVlan(), null));