/** * Puts the given value (Link) only in this local HashMap. Ideally used for * Link data listener events. * * @param ii the value's (Link's) InstanceIdentifier<Link> * @param value the Link to store locally. * @return the previous value associated with <tt>key</tt>, or * <tt>null</tt> if there was no mapping for <tt>key</tt> */ public synchronized V putLocally(InstanceIdentifier<Link> ii, V value) { Link l = ((Link) value); LOG.trace("Putting locally {}", l.getLinkId()); this.instanceIDs.put(ii, (K) l.getLinkId()); return this.linkHashMap.put((K) l.getLinkId(), value); }
public String id() { return this.link.getLinkId().getValue(); }
/** * @param currentLinks * Current links in topology * @param newLinks * New links in topology * @return Affected links by some change */ public List<Link> identifyChangedLink(List<Link> currentLinks, List<Link> newLinks) { List<Link> linksRemoved = new ArrayList<>(); // Identify if a link is affected in some protected Intent for (final Link link : currentLinks) { int value = 0; for (final Link linkk : newLinks) { if (link.getLinkId().equals(linkk.getLinkId())) { value++; break; } } if (value == 0) { // Topology hasChanged linksRemoved.add(link); } } return linksRemoved; }
private void addExistingLinks(Topology topology) { log.info("Topology Null Check: " + (topology == null)); List<Link> linkList = topology.getLink(); log.info("Link List Null Check: " + (linkList == null)); if (topology != null && linkList != null) { for (int i = 0; i < linkList.size(); i++) { Link link = linkList.get(i); log.info("Processing link " + i + ", " + link.getLinkId().getValue()); linkService.addLink(link); } } } @Override
/** * @param changedLink * Link that was updated/deleted * @return Identify which intents were affected */ public List<Intent> getAffectedIntents(Link changedLink) { List<Intent> affectedIntents = new ArrayList<>(); if (changedLink == null) return affectedIntents; for (final Intent key : ProtectedLinks.keySet()) { final List<List<Link>> linkss = ProtectedLinks.get(key); for (List<Link> list : linkss) { for (Link link : list) { if (link.getLinkId().getValue().equals(changedLink.getLinkId().getValue())) { if (!affectedIntents.contains(key)) affectedIntents.add(key); } } } } return affectedIntents; }
/** * Removes the given links both locally and on MD-SAL database. * * @param links * the links to remove. */ public synchronized void removeAll(List<Link> links) { for (final Map.Entry<InstanceIdentifier<Link>, K> e : this.instanceIDs .entrySet()) { LOG.debug("Links to remove from local & MD-SAL database", links.toString()); for (Link l : links) { if (e.getValue().equals(l.getLinkId())) { this.opProcessor .enqueueOperation(new HostTrackerOperation() { @Override public void applyOperation( ReadWriteTransaction tx) { tx.delete(LogicalDatastoreType.OPERATIONAL, e.getKey()); } }); this.linkHashMap.remove(e.getValue()); break; } } } }
public LinkBuilder(Link base) { this.key = base.key(); this._linkId = base.getLinkId(); this._destination = base.getDestination(); this._source = base.getSource(); this._supportingLink = base.getSupportingLink(); if (base instanceof LinkImpl) { LinkImpl impl = (LinkImpl) base; if (!impl.augmentation.isEmpty()) { this.augmentation = new HashMap<>(impl.augmentation); } } else if (base instanceof AugmentationHolder) { @SuppressWarnings("unchecked") Map<Class<? extends Augmentation<Link>>, Augmentation<Link>> aug =((AugmentationHolder<Link>) base).augmentations(); if (!aug.isEmpty()) { this.augmentation = new HashMap<>(aug); } } }
return false; if (!Objects.equals(_linkId, other.getLinkId())) { return false;
public LinkBuilder(Link base) { if (base.getKey() == null) { this._key = new LinkKey( base.getLinkId() ); this._linkId = base.getLinkId(); } else { this._key = base.getKey(); this._linkId = _key.getLinkId(); } this._destination = base.getDestination(); this._source = base.getSource(); this._supportingLink = base.getSupportingLink(); if (base instanceof LinkImpl) { LinkImpl impl = (LinkImpl) base; if (!impl.augmentation.isEmpty()) { this.augmentation = new HashMap<>(impl.augmentation); } } else if (base instanceof AugmentationHolder) { @SuppressWarnings("unchecked") AugmentationHolder<org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link> casted =(AugmentationHolder<org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link>) base; if (!casted.augmentations().isEmpty()) { this.augmentation = new HashMap<>(casted.augmentations()); } } }
@Override public void deleteLink(Link link) { synchronized (this) { this.linkIdIndexedLinks.remove(link.getLinkId().getValue()); deleteLinkFromTpIdIndexedLinks(srcTpIdIndexedLinks, link); deleteLinkFromTpIdIndexedLinks(dstTpIdIndexedLinks, link); deleteLinkFromNodeIdIndexedLinks(srcNodeIdIndexedLinks, link); deleteLinkFromNodeIdIndexedLinks(dstNodeIdIndexedLinks, link); log.info("Remove link with source as " + link.getSource().getSourceTp().getValue() + " and link id as "+ link.getLinkId().getValue()); } }
@Override public void addLink(Link link) { synchronized (this) { this.linkIdIndexedLinks.put(link.getLinkId().getValue(), link); addLinkToTpIdIndexedLinks(srcTpIdIndexedLinks, link); addLinkToTpIdIndexedLinks(dstTpIdIndexedLinks, link); addLinkToNodeIdIndexedLinks(srcNodeIdIndexedLinks, link); addLinkToNodeIdIndexedLinks(dstNodeIdIndexedLinks, link); log.info("Adding link with source as " + link.getSource().getSourceTp().getValue() + " and link id as " + link.getLinkId().getValue()); } }
/** * Add a VTN link information corresponding to the given MD-SAL * inter-switch link. * * @param luctx A {@link LinkUpdateContext} instance. * @param link A {@link Link} instance. * @throws VTNException An error occurred. */ private void add(LinkUpdateContext luctx, Link link) throws VTNException { LinkEdge le; try { le = new LinkEdge(link); } catch (RuntimeException e) { logger.debug("Ignore unsupported inter-switch link: " + link, e); return; } LinkId lid = link.getLinkId(); SalPort src = le.getSourcePort(); SalPort dst = le.getDestinationPort(); luctx.addVtnLink(lid, src, dst); }
/** * Puts the given link in the this local HashMap and into MD-SAL database. * * @param linkId * the key for the map * @param link * the value for the map * @return the old value from the local cache if present, null otherwise. */ @Override public synchronized V put(K linkId, V link) { final Link linkNode = ((Link) link); final InstanceIdentifier<Link> buildLinkIID = Utilities.buildLinkIID( linkNode.getKey(), topologyId); this.opProcessor.enqueueOperation(new HostTrackerOperation() { @Override public void applyOperation(ReadWriteTransaction tx) { tx.merge(LogicalDatastoreType.OPERATIONAL, buildLinkIID, linkNode, true); } }); LOG.trace("Putting MD-SAL {}", linkNode.getLinkId()); return putLocally(buildLinkIID, link); }
private void deleteLinkFromNodeIdIndexedLinks(Map<String, Set<String>> nodeIdIndexedLinks, Link link) { String key = link.getSource().getSourceNode().getValue(); String value = link.getLinkId().getValue(); deleteLinkFromIndexedLinks(nodeIdIndexedLinks, key, value); }
private void addLinkToTpIdIndexedLinks(Map<String, Set<String>> tpIdIndexedLinks, Link link) { String key = link.getSource().getSourceTp().getValue(); String value = link.getLinkId().getValue(); addLinkToIndexedLinks(tpIdIndexedLinks, key, value); }
private void deleteLinkFromTpIdIndexedLinks(Map<String, Set<String>> tpIdIndexedLinks, Link link) { String key = link.getSource().getSourceTp().getValue(); String value = link.getLinkId().getValue(); deleteLinkFromIndexedLinks(tpIdIndexedLinks, key, value); }
private void addLinkToNodeIdIndexedLinks(Map<String, Set<String>> nodeIdIndexedLinks, Link link) { String key = link.getSource().getSourceNode().getValue(); String value = link.getLinkId().getValue(); addLinkToIndexedLinks(nodeIdIndexedLinks, key, value); }
if (!(link.getLinkId().getValue().contains("host")))
/** * Initialize VTN network topology. * * @param luctx A {@link LinkUpdateContext} instance. * @param topology MD-SAL network topology. * @throws VTNException * An error occurred. */ private void initLinks(LinkUpdateContext luctx, Topology topology) throws VTNException { if (topology == null) { return; } List<Link> links = topology.getLink(); if (links == null) { return; } for (Link link: links) { SalPort src = SalPort.create(link.getSource()); SalPort dst = SalPort.create(link.getDestination()); if (src == null || dst == null) { LOG.debug("Ignore unsupported inter-switch link: {}", link); } else { luctx.addVtnLink(link.getLinkId(), src, dst); } } }
link = findGWLink(trans, fabricId, tpOnRouter, routerId); if (link != null) trans.delete(LogicalDatastoreType.OPERATIONAL, MdSalUtils.createLinkIId(fabricId, link.getLinkId()));