public void addEgressLink(Link link) { egressLinks.add(link); addEgessCp(link.src()); }
/** * Get links originating from the source device ID. * * @param links list of available links * @param source the device ID of the source device * @return the list of links with the given source */ private List<Link> getEgressLinks(Set<Link> links, final DeviceId source) { return links.stream() .filter(link -> link.src().deviceId().equals(source)) .collect(Collectors.toList()); }
@Override public Load load(Link link) { checkPermission(STATISTIC_READ); return load(link.src()); }
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(); }
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 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); }
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; }
@Override public int complete(Session session, CommandLine commandLine, List<String> candidates) { // Delegate string completer StringsCompleter delegate = new StringsCompleter(); // Fetch our service and feed it's offerings to the string completer LinkService service = AbstractShellCommand.get(LinkService.class); // Generate the device ID/port number identifiers SortedSet<String> strings = delegate.getStrings(); service.getLinks() .forEach(link -> strings.add(link.src().elementId().toString() + "/" + link.src().port())); // Now let the completer do the work for figuring out what to offer. return delegate.complete(session, commandLine, candidates); }
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 void updateFailoverGroup(PointToPointIntent intent, List<Link> links) { GroupKey groupKey = makeGroupKey(intent.id()); TrafficTreatment.Builder tBuilderIn = DefaultTrafficTreatment.builder(); ConnectPoint src = links.get(0).src(); tBuilderIn.setOutput(src.port()); GroupBucket bucket = DefaultGroupBucket.createFailoverGroupBucket(tBuilderIn.build(), src.port(), null); GroupBuckets addBuckets = new GroupBuckets(Collections.singletonList(bucket)); groupService.addBucketsToGroup(src.deviceId(), groupKey, addBuckets, groupKey, intent.appId()); }
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(); }