@Override public Link getLink(ConnectPoint src, ConnectPoint dst) { return links.get(linkKey(src, dst)); }
@Override public void addTrackedResources(Key intentKey, Collection<NetworkResource> resources) { for (NetworkResource resource : resources) { if (resource instanceof Link) { intentsByLink.put(linkKey((Link) resource), intentKey); } else if (resource instanceof ElementId) { intentsByDevice.put((ElementId) resource, intentKey); } } }
@Override public LinkKey read(Kryo kryo, Input input, Class<LinkKey> type) { ConnectPoint src = (ConnectPoint) kryo.readClassAndObject(input); ConnectPoint dst = (ConnectPoint) kryo.readClassAndObject(input); return LinkKey.linkKey(src, dst); } }
@Override public void removeTrackedResources(Key intentKey, Collection<NetworkResource> resources) { for (NetworkResource resource : resources) { if (resource instanceof Link) { intentsByLink.remove(linkKey((Link) resource), intentKey); } else if (resource instanceof ElementId) { intentsByDevice.remove(resource, intentKey); } } }
/** * Find available TributarySlots across path. * * @param intent * @param path path in OTU topology * @return Map of Linkey and Set of available TributarySlots on its ports */ private Map<LinkKey, Set<TributarySlot>> findAvailableTributarySlots(OpticalOduIntent intent, Path path) { Set<LinkKey> linkRequest = Sets.newHashSetWithExpectedSize(path.links().size()); for (int i = 0; i < path.links().size(); i++) { LinkKey link = linkKey(path.links().get(i)); linkRequest.add(link); } return findTributarySlots(intent, linkRequest); }
private void checkIntentsByLink(FlowRuleIntent installable, ServiceRefs svcRefs) { Set<Map.Entry<LinkKey, Key>> intentsByLink = getIntentsByLinkSet(svcRefs); installable.resources().forEach( rsrc -> { if (rsrc instanceof Link) { Link link = (Link) rsrc; LinkKey linkKey = LinkKey.linkKey(link); intentsByLink.stream() .filter(entry -> Objects.equals(entry.getKey(), linkKey) && Objects.equals(entry.getValue(), installable.key())) .findAny() .orElseGet(() -> { error("FAILED TO FIND LINK(" + link + ") for intents: " + installable.key()); return null; }); } } ); }
@Override public LinkEvent removeLink(ConnectPoint src, ConnectPoint dst) { final LinkKey key = linkKey(src, dst); Map<ProviderId, LinkDescription> descs = getOrCreateLinkDescriptions(key); synchronized (descs) { Link link = links.remove(key); descs.clear(); if (link != null) { srcLinks.remove(link.src().deviceId(), key); dstLinks.remove(link.dst().deviceId(), key); return new LinkEvent(LINK_REMOVED, link); } return null; } }
@Override protected void doExecute() { LinkService service = get(LinkService.class); Iterable<Link> links = uri != null ? service.getDeviceLinks(deviceId(uri)) : service.getLinks(); if (outputJson()) { print("%s", json(this, links)); } else { Tools.stream(links) .sorted(Comparator.comparing(link -> linkKey(link).toString())) .forEach(link -> { print(linkString(link)); }); } }
@Override public LinkEvent createOrUpdateLink(ProviderId providerId, LinkDescription linkDescription) { LinkKey key = linkKey(linkDescription.src(), linkDescription.dst()); Map<ProviderId, LinkDescription> descs = getOrCreateLinkDescriptions(key); synchronized (descs) { final Link oldLink = links.get(key); // update description createOrUpdateLinkDescription(descs, providerId, linkDescription); final Link newLink = composeLink(descs); if (oldLink == null) { return createLink(key, newLink); } return updateLink(key, oldLink, newLink); } }
if (reason instanceof LinkEvent) { LinkEvent linkEvent = (LinkEvent) reason; final LinkKey linkKey = linkKey(linkEvent.subject()); synchronized (intentsByLink) { Set<Key> intentKeys = intentsByLink.get(linkKey);
/** * Validates configuration against link configuration. * * @param linkDescription input * @return description combined with configuration or null if disallowed */ private LinkDescription validateLink(LinkDescription linkDescription) { BasicLinkConfig cfg = networkConfigService.getConfig(linkKey(linkDescription.src(), linkDescription.dst()), BasicLinkConfig.class); if (!isAllowed(cfg)) { log.trace("Link {} is not allowed", linkDescription); return null; } // test if bidirectional reverse configuration exists BasicLinkConfig cfgRev = networkConfigService.getConfig(linkKey(linkDescription.dst(), linkDescription.src()), BasicLinkConfig.class); LinkDescription description = linkDescription; if (cfgRev != null && cfgRev.isBidirectional()) { if (!cfgRev.isAllowed()) { log.trace("Link {} is not allowed (rev)", linkDescription); return null; } description = BasicLinkOperator.combine(cfgRev, description); } description = BasicLinkOperator.combine(cfg, description); return description; }
LinkKey link = linkKey(srcCp, dstCp); if (remove) { netCfgService.removeConfig(link, BasicLinkConfig.class);
MplsLabel mplsLabel = (MplsLabel) mplsLabels.get(linkKey(link)); if (mplsLabel == null) { throw new IntentCompilationException(ERROR_MPLS + link); MplsLabel transitMplsLabel = (MplsLabel) mplsLabels.get(linkKey(link)); if (transitMplsLabel == null) { throw new IntentCompilationException(ERROR_MPLS + link);
@Override public LinkEvent removeOrDownLink(ConnectPoint src, ConnectPoint dst) { Link link = getLink(src, dst); if (link == null) { return null; } if (link.isDurable()) { return link.state() == INACTIVE ? null : updateLink(linkKey(link.src(), link.dst()), link, new DefaultLink(link.providerId(), link.src(), link.dst(), link.type(), INACTIVE, link.isDurable(), link.annotations())); } return removeLink(src, dst); }
Set<TributarySlot> slots = slotsMap.get(linkKey(link)); OtuPort otuPort = (OtuPort) (deviceService.getPort(link.src().deviceId(), link.src().port())); OduSignalType otuPortOduSignalType =
try { context.providerService().linkDetected(ld); context.touchLink(LinkKey.linkKey(src, dst)); } catch (IllegalStateException e) { return true;