@Override public double cost(Link link, ResourceContext context) { //TODO: Usage of annotations are for transient solution. In future will be replaces with the // network config service / Projection model. switch (type) { case COST: if (link.annotations().value(COST) != null) { return Double.parseDouble(link.annotations().value(COST)); } //If cost annotations absent return -1[It is not L3 device] return -1; case TE_COST: if (link.annotations().value(TE_COST) != null) { return Double.parseDouble(link.annotations().value(TE_COST)); } //If TE cost annotations absent return -1[It is not L3 device] return -1; default: return -1; } }
@Override public double cost(Link link, ResourceContext context) { //TODO: Usage of annotations are for transient solution. In future will be replaces with the // network config service / Projection model. switch (type) { case COST: if (link.annotations().value(COST) != null) { return Double.parseDouble(link.annotations().value(COST)); } //If cost annotations absent return -1[It is not L3 device] return -1; case TE_COST: if (link.annotations().value(TE_COST) != null) { return Double.parseDouble(link.annotations().value(TE_COST)); } //If TE cost annotations absent return -1[It is not L3 device] return -1; default: return -1; } }
/** * Generates a link description from a link description entity. The endpoints * must be specified to indicate directionality. * * @param src the source ConnectPoint * @param dst the destination ConnectPoint * @param link the link config entity * @return a linkDescription based on the config */ public static LinkDescription descriptionOf( ConnectPoint src, ConnectPoint dst, Link link) { checkNotNull(src, "Must supply a source endpoint"); checkNotNull(dst, "Must supply a destination endpoint"); checkNotNull(link, "Must supply a link"); return new DefaultLinkDescription( src, dst, link.type(), link.isExpected(), (SparseAnnotations) link.annotations()); }
private LinkEvent updateLink(LinkKey key, Link oldLink, Link newLink) { if (oldLink.state() != newLink.state() || (oldLink.type() == INDIRECT && newLink.type() == DIRECT) || !AnnotationsUtil.isEqual(oldLink.annotations(), newLink.annotations())) { links.put(key, newLink); // strictly speaking following can be ommitted srcLinks.put(oldLink.src().deviceId(), key); dstLinks.put(oldLink.dst().deviceId(), key); return new LinkEvent(LINK_UPDATED, newLink); } return null; }
/** * Returns free resources for a given link obtaining from topology * information. * * @param link the target link * @return free resources */ private synchronized Set<ResourceAllocation> readOriginalFreeResources(Link link) { Annotations annotations = link.annotations(); Set<ResourceAllocation> allocations = new HashSet<>(); try { int waves = Integer.parseInt(annotations.value(AnnotationKeys.OPTICAL_WAVES)); for (int i = 1; i <= waves; i++) { allocations.add(new LambdaResourceAllocation(LambdaResource.valueOf(i))); } } catch (NumberFormatException e) { log.debug("No optical.wave annotation on link %s", link); } BandwidthResource bandwidth = DEFAULT_BANDWIDTH; try { bandwidth = new BandwidthResource( Bandwidth.mbps((Double.parseDouble(annotations.value(AnnotationKeys.BANDWIDTH))))); } catch (NumberFormatException e) { log.debug("No bandwidth annotation on link %s", link); } allocations.add( new BandwidthResourceAllocation(bandwidth)); return allocations; }
map.put("Te metric", link.annotations().value(TE_METRIC));
/** * Returns a formatted string representing the given link. * * @param link infrastructure link * @return formatted link string */ public static String linkString(Link link) { return String.format(FMT, link.src().deviceId(), link.src().port(), link.dst().deviceId(), link.dst().port(), link.type(), link.state(), annotations(link.annotations()), link.isExpected()); }
@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); }
public Weight weight(TopologyEdge edge) { log.debug("Link {} metric {}", edge.link(), edge.link().annotations().value("metric")); String metricString = edge.link().annotations().value("metric"); if (!metricString.isEmpty()) { double metric = Double.parseDouble(metricString);
/** * Returns a link in reverse direction. * * @param link to revese * @return reversed link */ Link reverse(Link link) { return DefaultLink.builder() .providerId(link.providerId()) .src(link.dst()) .dst(link.src()) .type(link.type()) .state(link.state()) .isExpected(link.isExpected()) .annotations(link.annotations()) .build(); }