@Override public Set<Link> getEgressLinks(ConnectPoint src) { Set<Link> egress = new HashSet<>(); synchronized (srcLinks) { for (LinkKey linkKey : srcLinks.get(src.deviceId())) { if (linkKey.src().equals(src)) { egress.add(links.get(linkKey)); } } } return egress; }
private void printInstallable(Intent installable) { print(" installable: %s %s", installable.getClass().getSimpleName(), installable.id()); print(" resources: %s", installable.resources().stream() .filter(r -> !(r instanceof Link)) .map(this::s) .collect(Collectors.joining(", "))); print(" links: %s", installable.resources().stream() .filter(Link.class::isInstance) .map(Link.class::cast) .map(LinkKey::linkKey) .map(l -> String.format("%s -> %s", l.src(), l.dst())) .collect(Collectors.joining(", "))); }
/** * Allocates labels and associates them to source * and destination ports of a link. * * @param links the links on which labels will be reserved * @param resourceConsumer the resource consumer * @param type the encapsulation type * @return the list of ports and associated labels */ public Map<ConnectPoint, Identifier<?>> assignLabelToPorts(Set<Link> links, ResourceConsumer resourceConsumer, EncapsulationType type) { Map<LinkKey, Identifier<?>> allocation = this.assignLabelToLinks(links, resourceConsumer, type); if (allocation.isEmpty()) { return Collections.emptyMap(); } Map<ConnectPoint, Identifier<?>> finalAllocation = Maps.newHashMap(); allocation.forEach((link, value) -> { finalAllocation.putIfAbsent(link.src(), value); finalAllocation.putIfAbsent(link.dst(), value); }); return ImmutableMap.copyOf(finalAllocation); }
private Map<LinkKey, Set<TributarySlot>> findTributarySlots(OpticalOduIntent intent, Set<LinkKey> links) { OduSignalType oduSignalType = OduSignalUtils.mappingCltSignalTypeToOduSignalType(intent.getSignalType()); int requestedTsNum = oduSignalType.tributarySlots(); Map<LinkKey, Set<TributarySlot>> slotsMap = new HashMap<>(); for (LinkKey link : links) { Set<TributarySlot> common = findCommonTributarySlotsOnCps(link.src(), link.dst()); if (common.isEmpty() || (common.size() < requestedTsNum)) { log.debug("Failed to find TributarySlots on link {} requestedTsNum={}", link, requestedTsNum); return Collections.emptyMap(); // failed to find enough available TributarySlots on a link } slotsMap.put(link, common.stream() .limit(requestedTsNum) .collect(Collectors.toSet())); } return slotsMap; }
private Set<Identifier<?>> getCandidates(LinkKey link, EncapsulationType type) { // Available ids on src port Set<Identifier<?>> availableIDsatSrc = getAvailableIDs(link.src(), type); // Available ids on dst port Set<Identifier<?>> availableIDsatDst = getAvailableIDs(link.dst(), type); // Create the candidate set doing an intersection of the previous sets return Sets.intersection(availableIDsatSrc, availableIDsatDst); }
private List<Resource> convertToResources(Map<LinkKey, Set<TributarySlot>> slotsMap) { // Same TributarySlots are used for both directions Set<Resource> resources = slotsMap.entrySet().stream() .flatMap(x -> x.getValue() .stream() .flatMap(ts -> Stream.of( Resources.discrete(x.getKey().src().deviceId(), x.getKey().src().port()) .resource().child(ts), Resources.discrete(x.getKey().dst().deviceId(), x.getKey().dst().port()) .resource().child(ts)))) .collect(Collectors.toSet()); return (ImmutableList.copyOf(resources)); }
@Override public void event(NetworkConfigEvent event) { LinkKey lk = (LinkKey) event.subject(); BasicLinkConfig cfg = (BasicLinkConfig) event.config().get(); log.debug("Detected link network config event {}", event.type()); if (!isAllowed(cfg)) { log.info("Kicking out links between {} and {}", lk.src(), lk.dst()); removeLink(lk.src(), lk.dst()); if (cfg.isBidirectional()) { removeLink(lk.dst(), lk.src()); } return; } doUpdate(lk.src(), lk.dst(), cfg); if (cfg.isBidirectional()) { doUpdate(lk.dst(), lk.src(), cfg); } }
@Override public void write(Kryo kryo, Output output, LinkKey object) { kryo.writeClassAndObject(output, object.src()); kryo.writeClassAndObject(output, object.dst()); }
providerService.linkVanished(new DefaultLinkDescription(e.getKey().src(), e.getKey().dst(), DIRECT));