@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); }
/** * Registers the bandwidth for source and destination points. * * @param linkDes link description instance * @param isisLink ISIS link instance */ private void registerBandwidth(LinkDescription linkDes, IsisLink isisLink) { if (isisLink == null) { log.error("Could not able to register bandwidth "); return; } IsisLinkTed isisLinkTed = isisLink.linkTed(); Bandwidth maxReservableBw = isisLinkTed.maximumReservableLinkBandwidth(); if (maxReservableBw != null) { if (maxReservableBw.compareTo(Bandwidth.bps(0)) == 0) { return; } //Configure bandwidth for src and dst port BandwidthCapacity config = networkConfigService.addConfig(linkDes.src(), BandwidthCapacity.class); config.capacity(maxReservableBw).apply(); config = networkConfigService.addConfig(linkDes.dst(), BandwidthCapacity.class); config.capacity(maxReservableBw).apply(); } } }
/** * 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; }
/** * Query bandwidth capacity on a port. * * @param did {@link DeviceId} * @param number {@link PortNumber} * @return bandwidth capacity */ private Optional<Bandwidth> queryBandwidth(DeviceId did, PortNumber number) { // Check and use netcfg first. ConnectPoint cp = new ConnectPoint(did, number); BandwidthCapacity config = netcfgService.getConfig(cp, BandwidthCapacity.class); if (config != null) { log.trace("Registering configured bandwidth {} for {}/{}", config.capacity(), did, number); return Optional.of(config.capacity()); } // populate bandwidth value, assuming portSpeed == bandwidth Port port = deviceService.getPort(did, number); if (port != null) { return Optional.of(Bandwidth.mbps(port.portSpeed())); } return Optional.empty(); }
@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 Bandwidth whose value is (this + value). * * @param value value to be added to this Frequency * @return this + value */ public Bandwidth add(Bandwidth value) { if (value instanceof LongBandwidth) { return Bandwidth.bps(this.bps + ((LongBandwidth) value).bps); } return Bandwidth.bps(this.bps + value.bps()); }
/** * Returns a Bandwidth whose value is (this - value). * * @param value value to be added to this Frequency * @return this - value */ public Bandwidth subtract(Bandwidth value) { if (value instanceof LongBandwidth) { return Bandwidth.bps(this.bps - ((LongBandwidth) value).bps); } return Bandwidth.bps(this.bps - value.bps()); }
@Override public int compareTo(Bandwidth other) { if (other instanceof LongBandwidth) { return ComparisonChain.start() .compare(this.bps, ((LongBandwidth) other).bps) .result(); } return ComparisonChain.start() .compare(this.bps, other.bps()) .result(); }
/** * Decodes a bandwidth constraint. * * @return bandwidth constraint object. */ private Constraint decodeBandwidthConstraint() { double bandwidth = nullIsIllegal(json.get(ConstraintCodec.BANDWIDTH), ConstraintCodec.BANDWIDTH + ConstraintCodec.MISSING_MEMBER_MESSAGE) .asDouble(); return new BandwidthConstraint(Bandwidth.bps(bandwidth)); }
/** * Encodes a bandwidth constraint. * * @return JSON ObjectNode representing the constraint */ private ObjectNode encodeBandwidthConstraint() { checkNotNull(constraint, "Bandwidth constraint cannot be null"); final BandwidthConstraint bandwidthConstraint = (BandwidthConstraint) constraint; return context.mapper().createObjectNode() .put("bandwidth", bandwidthConstraint.bandwidth().bps()); }
/** * Constructs a builder with a given queue description. * * @param queueDescription queue description */ private Builder(QueueDescription queueDescription) { if (queueDescription.maxRate().isPresent()) { otherConfigs.put(MAX_RATE, String.valueOf((long) queueDescription.maxRate().get().bps())); } if (queueDescription.minRate().isPresent()) { otherConfigs.put(MIN_RATE, String.valueOf((long) queueDescription.minRate().get().bps())); } if (queueDescription.burst().isPresent()) { otherConfigs.put(BURST, queueDescription.burst().get().toString()); } if (queueDescription.priority().isPresent()) { otherConfigs.put(PRIORITY, queueDescription.priority().get().toString()); } if (queueDescription.dscp().isPresent()) { dscp = Optional.of(queueDescription.dscp().get().longValue()); } externalIds.putAll(((DefaultAnnotations) queueDescription.annotations()).asMap()); externalIds.put(QUEUE_EXTERNAL_ID_KEY, queueDescription.queueId().name()); }
/** * Constructs a builder with a given Qos description. * * @param qosDesc Qos description */ private Builder(QosDescription qosDesc) { if (qosDesc.maxRate().isPresent()) { otherConfigs.put(MAX_RATE, String.valueOf((long) qosDesc.maxRate().get().bps())); } if (qosDesc.cir().isPresent()) { otherConfigs.put(CIR, qosDesc.cir().get().toString()); } if (qosDesc.cbs().isPresent()) { otherConfigs.put(CBS, qosDesc.cbs().get().toString()); } if (qosDesc.queues().isPresent()) { Map<Long, String> map = new HashMap<>(); qosDesc.queues().get().forEach((k, v) -> map.put(k, v.queueId().name())); queues = Optional.ofNullable(map); } type = qosDesc.type() == QosDescription.Type.EGRESS_POLICER ? QOS_EGRESS_POLICER : QOS_TYPE_PREFIX.concat(qosDesc.type().name().toLowerCase()); externalIds.putAll(((DefaultAnnotations) qosDesc.annotations()).asMap()); externalIds.put(QOS_EXTERNAL_ID_KEY, qosDesc.qosId().name()); }
/** * Finds and returns {@link BandwidthResourceAllocation} object from a given * set. * * @param freeRes a set of ResourceAllocation object. * @return {@link BandwidthResourceAllocation} object if found, otherwise * {@link BandwidthResourceAllocation} object with 0 bandwidth * */ private synchronized BandwidthResourceAllocation getBandwidth( Set<ResourceAllocation> freeRes) { for (ResourceAllocation res : freeRes) { if (res.type() == ResourceType.BANDWIDTH) { return (BandwidthResourceAllocation) res; } } return new BandwidthResourceAllocation(new BandwidthResource(Bandwidth.bps(0))); }
double bw = bwConstraint.bandwidth().bps();
/** * Builds the annotation details. * * @param annotationBuilder default annotation builder instance * @param isisLink ISIS link instance * @return annotation builder instance */ private DefaultAnnotations.Builder buildAnnotations(DefaultAnnotations.Builder annotationBuilder, IsisLink isisLink) { int administrativeGroup = 0; long teMetric = 0; Bandwidth maxReservableBandwidth = Bandwidth.bps(0); String routerId = null; String neighborId = null; //TE Info IsisLinkTed isisLinkTed = isisLink.linkTed(); log.info("Ted Information: {}", isisLinkTed.toString()); administrativeGroup = isisLinkTed.administrativeGroup(); teMetric = isisLinkTed.teDefaultMetric(); maxReservableBandwidth = isisLinkTed.maximumReservableLinkBandwidth(); routerId = isisLink.localSystemId(); neighborId = isisLink.remoteSystemId(); annotationBuilder.set(ADMINISTRATIVEGROUP, String.valueOf(administrativeGroup)); annotationBuilder.set(TE_METRIC, String.valueOf(teMetric)); annotationBuilder.set(MAXRESERVABLEBANDWIDTH, String.valueOf(maxReservableBandwidth)); annotationBuilder.set(ROUTERID, String.valueOf(routerId)); annotationBuilder.set(NEIGHBORID, String.valueOf(neighborId)); return annotationBuilder; }
freeRes.remove(ba); freeRes.add(new BandwidthResourceAllocation( new BandwidthResource(Bandwidth.bps(newBandwidth)))); break; case LAMBDA: