public void addIngressLink(Link link) { ingressLinks.add(link); addIngressCp(link.dst()); }
private ImmutableSet<ConnectPoint> findInfrastructurePoints() { ImmutableSet.Builder<ConnectPoint> builder = ImmutableSet.builder(); for (TopologyEdge edge : graph.getEdges()) { builder.add(edge.link().src()); builder.add(edge.link().dst()); } return builder.build(); }
private LinkEvent createLink(LinkKey key, Link newLink) { links.put(key, newLink); srcLinks.put(newLink.src().deviceId(), key); dstLinks.put(newLink.dst().deviceId(), key); return new LinkEvent(LINK_ADDED, newLink); }
public String pathToString(List<Link> links) { StringBuilder builder = new StringBuilder(); builder.append("{"); for (Link link : links) { builder.append("(Device:" + link.src().deviceId() + " Port:" + link.src().port().toLong()); builder.append(" Device:" + link.dst().deviceId() + " Port:" + link.dst().port().toLong()); builder.append(")"); } builder.append("}"); return builder.toString(); }
private void allocateIntentBandwidth(PointToPointIntent intent, Path path) { ConnectPoint ingressCP = intent.filteredIngressPoint().connectPoint(); ConnectPoint egressCP = intent.filteredEgressPoint().connectPoint(); List<ConnectPoint> pathCPs = path.links().stream() .flatMap(l -> Stream.of(l.src(), l.dst())) .collect(Collectors.toList()); pathCPs.add(ingressCP); pathCPs.add(egressCP); allocateBandwidth(intent, pathCPs); }
private void removeLinks(Set<Link> links, boolean isSoftRemove) { for (Link link : links) { LinkEvent event = isSoftRemove ? store.removeOrDownLink(link.src(), link.dst()) : store.removeLink(link.src(), link.dst()); if (event != null) { log.info("Link {} removed/vanished", event.subject()); post(event); } } }
private boolean isAvailableTributarySlots(OpticalOduIntent intent, Link link) { OduSignalType oduSignalType = OduSignalUtils.mappingCltSignalTypeToOduSignalType(intent.getSignalType()); int requestedTsNum = oduSignalType.tributarySlots(); Set<TributarySlot> common = findCommonTributarySlotsOnCps(link.src(), link.dst()); if (common.isEmpty() || (common.size() < requestedTsNum)) { log.debug("Not enough available TributarySlots on link {} requestedTsNum={}", link, requestedTsNum); return false; } return true; }
private ImmutableSet<ConnectPoint> findInfrastructurePoints() { ImmutableSet.Builder<ConnectPoint> builder = ImmutableSet.builder(); for (TopologyEdge edge : graph.getEdges()) { if (edge.link().type() == Type.EDGE) { // exclude EDGE link from infrastructure link // - Device <-> Host // - Device <-> remote domain Device continue; } builder.add(edge.link().src()); builder.add(edge.link().dst()); } return builder.build(); }
private FilteredConnectPoint getFilteredPointFromLink(Link link) { FilteredConnectPoint filteredConnectPoint; if (link.src().elementId() instanceof DeviceId) { filteredConnectPoint = new FilteredConnectPoint(link.src()); } else if (link.dst().elementId() instanceof DeviceId) { filteredConnectPoint = new FilteredConnectPoint(link.dst()); } else { throw new IntentCompilationException(DEVICE_ID_NOT_FOUND); } return filteredConnectPoint; }
@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 boolean isValid(Link link, ResourceContext context) { changedBwValue = requestBwValue; if (links.contains(link)) { changedBwValue = requestBwValue.isGreaterThan(sharedBwValue) ? requestBwValue.subtract(sharedBwValue) : Bandwidth.bps(0); } return Stream .of(link.src(), link.dst()) .map(cp -> Resources.continuous(cp.deviceId(), cp.port(), Bandwidth.class).resource( changedBwValue.bps())).allMatch(context::isAvailable); }
@Override public boolean isValid(Link link, ResourceContext context) { changedBwValue = requestBwValue; if (links.contains(link)) { changedBwValue = requestBwValue.isGreaterThan(sharedBwValue) ? requestBwValue.subtract(sharedBwValue) : Bandwidth.bps(0); } return Stream .of(link.src(), link.dst()) .map(cp -> Resources.continuous(cp.deviceId(), cp.port(), Bandwidth.class).resource( changedBwValue.bps())).allMatch(context::isAvailable); }
/** * 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()); }
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; }
private void wipeOutLinks() { print("Wiping links"); LinkAdminService linkAdminService = get(LinkAdminService.class); while (linkAdminService.getLinkCount() > 0) { try { for (Link link : linkAdminService.getLinks()) { linkAdminService.removeLinks(link.src()); linkAdminService.removeLinks(link.dst()); } } catch (Exception e) { log.info("Unable to wipe-out links", e); } } }
private LinkDescription description(Link link, String key, String value) { checkNotNull(key, "Key cannot be null"); DefaultAnnotations.Builder builder = DefaultAnnotations.builder(); if (value != null) { builder.set(key, value); } else { builder.remove(key); } return new DefaultLinkDescription(link.src(), link.dst(), link.type(), link.isExpected(), builder.build()); }
private void processLinkEvent(LinkEvent event) { // negative Link event can result in increase of edge ports boolean addEdgePort = event.type() == LinkEvent.Type.LINK_REMOVED; // but if the Link is an Edge type, it will be the opposite if (event.subject().type() == Type.EDGE) { addEdgePort = !addEdgePort; } if (addEdgePort) { addEdgePort(event.subject().src()); addEdgePort(event.subject().dst()); } else { removeEdgePort(event.subject().src()); removeEdgePort(event.subject().dst()); } }
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(); }