/** * Test if specified Link is intact. * * @param link to test * @return true if link is intact */ private boolean isLive(Link link) { // Only testing link state for now // in the long run, consider verifying OAM state on ports return link.state() != State.INACTIVE; }
@Override public Iterable<Link> getActiveLinks() { checkPermission(LINK_READ); return FluentIterable.from(getLinks()) .filter(input -> input.state() == State.ACTIVE); }
@Override public ObjectNode encode(Link link, CodecContext context) { checkNotNull(link, "Link cannot be null"); JsonCodec<ConnectPoint> codec = context.codec(ConnectPoint.class); ObjectNode result = context.mapper().createObjectNode(); result.set(SRC, codec.encode(link.src(), context)); result.set(DST, codec.encode(link.dst(), context)); result.put(TYPE, link.type().toString()); if (link.state() != null) { result.put(STATE, link.state().toString()); } return annotate(result, link, context); }
@Override public double weight(TopologyEdge edge) { // To force preference to use direct paths first, make indirect // links as expensive as the linear vertex traversal. return edge.link().state() == ACTIVE ? (edge.link().type() == INDIRECT ? indirectLinkCost : 1) : -1; } }
@Override public double weight(TopologyEdge edge) { return (edge.link().state() == INACTIVE) || (edge.link().type() == INDIRECT) ? -1 : 1; } }
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; }
@Override public Weight weight(TopologyEdge edge) { return (edge.link().state() == INACTIVE) || (edge.link().type() == INDIRECT) ? getNonViableWeight() : new ScalarWeight(HOP_WEIGHT_VALUE); } }
/** * 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()); }
if (resource instanceof Link) { Link link = (Link) resource; if (link.state() == Link.State.INACTIVE) { setPathsToRemove(intent); } else if (link instanceof EdgeLink) {
private Link reverseLink(Link link) { return DefaultLink.builder().providerId(link.providerId()) .src(link.dst()) .dst(link.src()) .type(link.type()) .state(link.state()) .isExpected(link.isExpected()) .build(); }
@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); }
/** * 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(); }
if (edge.link().state() == Link.State.INACTIVE) { return ScalarWeight.toWeight(-1);