@Override protected Stream<Location> getVrfLocations(Vrf vrf) { return vrf.getInterfaces().values().stream() .map(iface -> new InterfaceLinkLocation(iface.getOwner().getHostname(), iface.getName())); } }
@Override public Set<Location> resolve(SpecifierContext ctxt) { return ctxt.getConfigs().values().stream() .flatMap(node -> node.getAllInterfaces().values().stream()) .map(iface -> new InterfaceLinkLocation(iface.getOwner().getHostname(), iface.getName())) .collect(ImmutableSet.toImmutableSet()); } }
private Stream<Edge> generateRules_NodeInterfaceDisposition_Disposition( BiFunction<String, String, StateExpr> nodeInterfaceDispositionConstructor, StateExpr dispositionNode, Set<String> finalNodes) { return finalNodes.stream() .map(_configs::get) .filter(Objects::nonNull) // remove finalNodes that don't exist on this network .flatMap(c -> c.getAllInterfaces().values().stream()) .map( iface -> { String nodeNode = iface.getOwner().getHostname(); String ifaceName = iface.getName(); return new Edge( nodeInterfaceDispositionConstructor.apply(nodeNode, ifaceName), dispositionNode); }); }
@Override public Set<Location> resolve(SpecifierContext ctxt) { return _nodeSpecifier.resolve(ctxt).stream() .map(n -> ctxt.getConfigs().get(n).getAllInterfaces().values()) .flatMap(Collection::stream) .map(iface -> new InterfaceLocation(iface.getOwner().getHostname(), iface.getName())) .collect(Collectors.toSet()); } }
@Override public Set<Location> resolve(SpecifierContext ctxt) { return ctxt.getConfigs().values().stream() .flatMap(node -> node.getAllInterfaces().values().stream()) .map(iface -> new InterfaceLocation(iface.getOwner().getHostname(), iface.getName())) .collect(ImmutableSet.toImmutableSet()); } }
@Override public Set<Location> resolve(SpecifierContext ctxt) { return _interfaceSpecifier.resolve(ctxt.getConfigs().keySet(), ctxt).stream() .map(iface -> new InterfaceLocation(iface.getOwner().getHostname(), iface.getName())) .collect(Collectors.toSet()); } }
@Override protected Stream<Location> getVrfLocations(Vrf vrf) { return vrf.getInterfaces().values().stream() .map(iface -> new InterfaceLocation(iface.getOwner().getHostname(), iface.getName())); } }
public NodeInterfacePair(Interface iface) { this(iface.getOwner().getHostname(), iface.getName()); }
@VisibleForTesting IpSpace computeIpsAssignedToThisInterface(Interface iface) { Set<Ip> ips = _interfaceOwnedIps.get(iface.getOwner().getHostname()).get(iface.getName()); if (ips == null || ips.isEmpty()) { return EmptyIpSpace.INSTANCE; } IpWildcardSetIpSpace.Builder ipsAssignedToThisInterfaceBuilder = IpWildcardSetIpSpace.builder(); ips.forEach(ip -> ipsAssignedToThisInterfaceBuilder.including(new IpWildcard(ip))); IpWildcardSetIpSpace ipsAssignedToThisInterface = ipsAssignedToThisInterfaceBuilder.build(); return ipsAssignedToThisInterface; }
@Override protected Location getLocation(Interface iface) { return new InterfaceLinkLocation(iface.getOwner().getHostname(), iface.getName()); } }
@Override protected Location getLocation(Interface iface) { return new InterfaceLocation(iface.getOwner().getHostname(), iface.getName()); } }
@Override protected Location getLocation(Interface iface) { return new InterfaceLinkLocation(iface.getOwner().getHostname(), iface.getName()); } }
@Override protected Location getLocation(Interface iface) { return new InterfaceLocation(iface.getOwner().getHostname(), iface.getName()); } }
@Override public Set<Interface> resolve(Set<String> nodes, SpecifierContext ctxt) { InterfaceGroup interfaceGroup = ctxt.getReferenceBook(_bookName) .orElseThrow( () -> new NoSuchElementException("ReferenceBook '" + _bookName + "' not found")) .getInterfaceGroup(_interfaceGroupName) .orElseThrow( () -> new NoSuchElementException( "InterfaceGroup '" + _interfaceGroupName + "' not found in ReferenceBook '" + _bookName + "'")); return nodes.stream() .map(n -> ctxt.getConfigs().get(n).getAllInterfaces().values()) .flatMap(Collection::stream) // we have a stream of Interfaces now .filter( v -> interfaceGroup .getInterfaces() .contains(new NodeInterfacePair(v.getOwner().getHostname(), v.getName()))) .collect(Collectors.toSet()); } }
@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); } }
private Stream<Edge> generateRules_PreInInterface_PostInVrf() { return _configs.values().stream() .map(Configuration::getVrfs) .map(Map::values) .flatMap(Collection::stream) .flatMap(vrf -> vrf.getInterfaces().values().stream()) .map( iface -> { String aclName = iface.getIncomingFilterName(); String nodeName = iface.getOwner().getHostname(); String vrfName = iface.getVrfName(); String ifaceName = iface.getName(); PreInInterface preState = new PreInInterface(nodeName, ifaceName); PostInVrf postState = new PostInVrf(nodeName, vrfName); BDD inAclBDD = ignorableAclPermitBDD(nodeName, aclName); Transition transition = compose( constraint(inAclBDD), _bddIncomingTransformations.get(nodeName).get(ifaceName)); return new Edge(preState, postState, transition); }); }
/** Deactivate an interface if it is blacklisted or its dependencies are not active */ private static void deactivateInterfaceIfNeeded(Interface iface) { Configuration config = iface.getOwner(); Set<Dependency> dependencies = iface.getDependencies(); if (dependencies.stream() // Look at bind dependencies .filter(d -> d.getType() == DependencyType.BIND) .map(d -> config.getAllInterfaces().get(d.getInterfaceName())) // Find any missing or inactive interfaces .anyMatch(parent -> parent == null || !parent.getActive())) { iface.setActive(false); } // Look at aggregate dependencies only now Set<Dependency> aggregateDependencies = dependencies.stream() .filter(d -> d.getType() == DependencyType.AGGREGATE) .collect(ImmutableSet.toImmutableSet()); if (iface.getInterfaceType() == InterfaceType.AGGREGATED && aggregateDependencies.stream() // Extract existing and active interfaces .map(d -> config.getAllInterfaces().get(d.getInterfaceName())) .filter(Objects::nonNull) .noneMatch(Interface::getActive)) { iface.setActive(false); } }
private Stream<Edge> generateRules_PreInInterface_NodeDropAclIn() { return _configs.values().stream() .map(Configuration::getVrfs) .map(Map::values) .flatMap(Collection::stream) .flatMap(vrf -> vrf.getInterfaces().values().stream()) .filter(iface -> iface.getIncomingFilter() != null) .map( i -> { String acl = i.getIncomingFilterName(); String node = i.getOwner().getHostname(); String iface = i.getName(); BDD aclDenyBDD = ignorableAclDenyBDD(node, acl); return new Edge( new PreInInterface(node, iface), new NodeDropAclIn(node), validSource(aclDenyBDD, node), eraseSourceAfter(aclDenyBDD, node)); }); }
@Test public void testIpInterfaceOwnersWithVrrp() { Map<String, Configuration> configs = setupVrrpTestCase(true); Map<Ip, Map<String, Set<String>>> interfaceOwners = computeIpInterfaceOwners(computeNodeInterfaces(configs), false); assertThat( interfaceOwners, hasEntry( equalTo(_i1.getAddress().getIp()), hasEntry(equalTo(_i1.getOwner().getHostname()), contains(_i1.getName())))); assertThat( interfaceOwners, hasEntry( equalTo(_i2.getAddress().getIp()), hasEntry(equalTo(_i2.getOwner().getHostname()), contains(_i2.getName())))); assertThat( interfaceOwners, hasEntry( equalTo(_virtInterfaceAddr.getIp()), hasEntry(equalTo(_i2.getOwner().getHostname()), contains(_i2.getName())))); } }
@Test public void testInterfaceBuilder() { NetworkFactory nf = new NetworkFactory(); Interface.Builder ib = nf.interfaceBuilder(); Interface i1 = ib.build(); Interface i2 = ib.build(); Configuration c = nf.configurationBuilder().setConfigurationFormat(CONFIG_FORMAT).build(); Vrf vrf = nf.vrfBuilder().setOwner(c).build(); ib.setOwner(c); Interface i3 = ib.build(); ib.setVrf(vrf); Interface i4 = ib.build(); assertThat(i1.getName(), is(notNullValue())); assertThat(i1.getName(), not(equalTo(i2.getName()))); assertThat(c.getAllInterfaces(), not(hasKey(i1.getName()))); assertThat(i2.getName(), is(notNullValue())); assertThat(c.getAllInterfaces(), not(hasKey(i2.getName()))); assertThat(c.getAllInterfaces(), hasKey(i3.getName())); assertThat(i3.getOwner(), sameInstance(c)); assertThat(vrf.getInterfaces(), not(hasKey(i3.getName()))); assertThat(c.getAllInterfaces(), hasKey(i4.getName())); assertThat(vrf.getInterfaces(), hasKey(i4.getName())); assertThat(i4.getVrf(), sameInstance(vrf)); }