mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-18 10:51:04 +02:00
ONOS-3732 Bandwidth resource registration using netcfg.
- Uses netcfg defined value as available resource if defined, else uses port speed as available Bandwidth resource Change-Id: I2dde9a9194025194ed8785b4608f064debab182b
This commit is contained in:
parent
34b55b6aea
commit
1d7c9cbe6d
@ -113,9 +113,15 @@ public class ResourcesCommand extends AbstractShellCommand {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (resource instanceof ContinuousResource) {
|
if (resource instanceof ContinuousResource) {
|
||||||
|
String s = ((String) resource.last());
|
||||||
|
String simpleName = s.substring(s.lastIndexOf('.') + 1);
|
||||||
print("%s%s: %f", Strings.repeat(" ", level),
|
print("%s%s: %f", Strings.repeat(" ", level),
|
||||||
resource.last(),
|
simpleName,
|
||||||
|
// Note: last() does not return, what we've registered
|
||||||
|
// following does not work
|
||||||
|
//((Class<?>) resource.last()).getSimpleName(),
|
||||||
((ContinuousResource) resource).value());
|
((ContinuousResource) resource).value());
|
||||||
// Continuous resource is terminal node, stop here
|
// Continuous resource is terminal node, stop here
|
||||||
return;
|
return;
|
||||||
|
@ -190,6 +190,17 @@ public abstract class Config<S> {
|
|||||||
return object.path(name).asBoolean(defaultValue);
|
return object.path(name).asBoolean(defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears the specified property.
|
||||||
|
*
|
||||||
|
* @param name property name
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
protected Config<S> clear(String name) {
|
||||||
|
object.remove(name);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the specified property as a boolean or clears it if null value given.
|
* Sets the specified property as a boolean or clears it if null value given.
|
||||||
*
|
*
|
||||||
@ -437,7 +448,38 @@ public abstract class Config<S> {
|
|||||||
*/
|
*/
|
||||||
protected boolean isNumber(String field, FieldPresence presence, long... minMax) {
|
protected boolean isNumber(String field, FieldPresence presence, long... minMax) {
|
||||||
JsonNode node = object.path(field);
|
JsonNode node = object.path(field);
|
||||||
return isValid(node, presence, (node.isLong() || node.isInt()) &&
|
return isValid(node, presence, node.isNumber() &&
|
||||||
|
(minMax.length > 0 && minMax[0] <= node.asLong() || minMax.length < 1) &&
|
||||||
|
(minMax.length > 1 && minMax[1] > node.asLong() || minMax.length < 2));
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Indicates whether the specified field holds a valid number.
|
||||||
|
*
|
||||||
|
* @param field JSON field name
|
||||||
|
* @param presence specifies if field is optional or mandatory
|
||||||
|
* @param minMax optional min/max values
|
||||||
|
* @return true if valid; false otherwise
|
||||||
|
* @throws IllegalArgumentException if field is present, but not valid
|
||||||
|
*/
|
||||||
|
protected boolean isNumber(String field, FieldPresence presence, double... minMax) {
|
||||||
|
JsonNode node = object.path(field);
|
||||||
|
return isValid(node, presence, node.isNumber() &&
|
||||||
|
(minMax.length > 0 && minMax[0] <= node.asDouble() || minMax.length < 1) &&
|
||||||
|
(minMax.length > 1 && minMax[1] > node.asDouble() || minMax.length < 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates whether the specified field holds a valid integer.
|
||||||
|
*
|
||||||
|
* @param field JSON field name
|
||||||
|
* @param presence specifies if field is optional or mandatory
|
||||||
|
* @param minMax optional min/max values
|
||||||
|
* @return true if valid; false otherwise
|
||||||
|
* @throws IllegalArgumentException if field is present, but not valid
|
||||||
|
*/
|
||||||
|
protected boolean isIntegralNumber(String field, FieldPresence presence, long... minMax) {
|
||||||
|
JsonNode node = object.path(field);
|
||||||
|
return isValid(node, presence, node.isIntegralNumber() &&
|
||||||
(minMax.length > 0 && minMax[0] <= node.asLong() || minMax.length < 1) &&
|
(minMax.length > 0 && minMax[0] <= node.asLong() || minMax.length < 1) &&
|
||||||
(minMax.length > 1 && minMax[1] > node.asLong() || minMax.length < 2));
|
(minMax.length > 1 && minMax[1] > node.asLong() || minMax.length < 2));
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,85 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016 Open Networking Laboratory
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.onosproject.net.newresource;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import org.onlab.util.Bandwidth;
|
||||||
|
import org.onosproject.net.ConnectPoint;
|
||||||
|
import org.onosproject.net.config.Config;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.google.common.annotations.Beta;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration to specify maximum available bandwidth resource (Capacity) on a port.
|
||||||
|
*/
|
||||||
|
@Beta
|
||||||
|
public class BandwidthCapacity extends Config<ConnectPoint> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* netcfg ConfigKey for {@link BandwidthCapacity}.
|
||||||
|
*/
|
||||||
|
public static final String CONFIG_KEY = "bandwidthCapacity";
|
||||||
|
|
||||||
|
// JSON key
|
||||||
|
private static final String CAPACITY = "capacityMbps";
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(BandwidthCapacity.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isValid() {
|
||||||
|
// Open for extension (adding fields) in the future,
|
||||||
|
// must have CAPACITY field.
|
||||||
|
return isNumber(CAPACITY, FieldPresence.MANDATORY);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the Available Bandwidth resource (Capacity).
|
||||||
|
*
|
||||||
|
* @param bandwidth value to set.
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public BandwidthCapacity capacity(Bandwidth bandwidth) {
|
||||||
|
checkNotNull(bandwidth);
|
||||||
|
|
||||||
|
// TODO current Bandwidth API end up value converted to double
|
||||||
|
setOrClear(CAPACITY, bandwidth.bps());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Available Bandwidth resource (Capacity).
|
||||||
|
*
|
||||||
|
* @return {@link Bandwidth}
|
||||||
|
*/
|
||||||
|
public Bandwidth capacity() {
|
||||||
|
JsonNode v = object.path(CAPACITY);
|
||||||
|
|
||||||
|
if (v.isIntegralNumber()) {
|
||||||
|
|
||||||
|
return Bandwidth.mbps(v.asLong());
|
||||||
|
} else if (v.isFloatingPointNumber()) {
|
||||||
|
|
||||||
|
return Bandwidth.mbps(v.asDouble());
|
||||||
|
} else {
|
||||||
|
log.warn("Unexpected JsonNode for {}: {}", CAPACITY, v);
|
||||||
|
return Bandwidth.mbps(v.asDouble());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -16,6 +16,7 @@
|
|||||||
package org.onosproject.net.newresource;
|
package org.onosproject.net.newresource;
|
||||||
|
|
||||||
import com.google.common.annotations.Beta;
|
import com.google.common.annotations.Beta;
|
||||||
|
|
||||||
import org.onosproject.net.DeviceId;
|
import org.onosproject.net.DeviceId;
|
||||||
import org.onosproject.net.PortNumber;
|
import org.onosproject.net.PortNumber;
|
||||||
|
|
||||||
|
@ -18,7 +18,9 @@ package org.onosproject.net.newresource.impl;
|
|||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import org.onlab.packet.MplsLabel;
|
import org.onlab.packet.MplsLabel;
|
||||||
import org.onlab.packet.VlanId;
|
import org.onlab.packet.VlanId;
|
||||||
|
import org.onlab.util.Bandwidth;
|
||||||
import org.onlab.util.ItemNotFoundException;
|
import org.onlab.util.ItemNotFoundException;
|
||||||
|
import org.onosproject.net.ConnectPoint;
|
||||||
import org.onosproject.net.Device;
|
import org.onosproject.net.Device;
|
||||||
import org.onosproject.net.DeviceId;
|
import org.onosproject.net.DeviceId;
|
||||||
import org.onosproject.net.OchSignal;
|
import org.onosproject.net.OchSignal;
|
||||||
@ -29,17 +31,20 @@ import org.onosproject.net.behaviour.LambdaQuery;
|
|||||||
import org.onosproject.net.behaviour.MplsQuery;
|
import org.onosproject.net.behaviour.MplsQuery;
|
||||||
import org.onosproject.net.behaviour.TributarySlotQuery;
|
import org.onosproject.net.behaviour.TributarySlotQuery;
|
||||||
import org.onosproject.net.behaviour.VlanQuery;
|
import org.onosproject.net.behaviour.VlanQuery;
|
||||||
|
import org.onosproject.net.config.NetworkConfigService;
|
||||||
import org.onosproject.net.device.DeviceEvent;
|
import org.onosproject.net.device.DeviceEvent;
|
||||||
import org.onosproject.net.device.DeviceListener;
|
import org.onosproject.net.device.DeviceListener;
|
||||||
import org.onosproject.net.device.DeviceService;
|
import org.onosproject.net.device.DeviceService;
|
||||||
import org.onosproject.net.driver.DriverHandler;
|
import org.onosproject.net.driver.DriverHandler;
|
||||||
import org.onosproject.net.driver.DriverService;
|
import org.onosproject.net.driver.DriverService;
|
||||||
import org.onosproject.net.newresource.ResourceAdminService;
|
import org.onosproject.net.newresource.ResourceAdminService;
|
||||||
|
import org.onosproject.net.newresource.BandwidthCapacity;
|
||||||
import org.onosproject.net.newresource.Resource;
|
import org.onosproject.net.newresource.Resource;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -56,21 +61,25 @@ final class ResourceDeviceListener implements DeviceListener {
|
|||||||
private final ResourceAdminService adminService;
|
private final ResourceAdminService adminService;
|
||||||
private final DeviceService deviceService;
|
private final DeviceService deviceService;
|
||||||
private final DriverService driverService;
|
private final DriverService driverService;
|
||||||
|
private final NetworkConfigService netcfgService;
|
||||||
private final ExecutorService executor;
|
private final ExecutorService executor;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an instance with the specified ResourceAdminService and ExecutorService.
|
* Creates an instance with the specified ResourceAdminService and ExecutorService.
|
||||||
*
|
*
|
||||||
* @param adminService instance invoked to register resources
|
* @param adminService instance invoked to register resources
|
||||||
* @param deviceService {@link DeviceService} to be used
|
* @param deviceService {@link DeviceService} to be used
|
||||||
* @param driverService {@link DriverService} to be used
|
* @param driverService {@link DriverService} to be used
|
||||||
|
* @param netcfgService {@link NetworkConfigService} to be used.
|
||||||
* @param executor executor used for processing resource registration
|
* @param executor executor used for processing resource registration
|
||||||
*/
|
*/
|
||||||
ResourceDeviceListener(ResourceAdminService adminService, DeviceService deviceService, DriverService driverService,
|
ResourceDeviceListener(ResourceAdminService adminService, DeviceService deviceService, DriverService driverService,
|
||||||
ExecutorService executor) {
|
NetworkConfigService netcfgService, ExecutorService executor) {
|
||||||
this.adminService = checkNotNull(adminService);
|
this.adminService = checkNotNull(adminService);
|
||||||
this.deviceService = checkNotNull(deviceService);
|
this.deviceService = checkNotNull(deviceService);
|
||||||
this.driverService = checkNotNull(driverService);
|
this.driverService = checkNotNull(driverService);
|
||||||
|
this.netcfgService = checkNotNull(netcfgService);
|
||||||
this.executor = checkNotNull(executor);
|
this.executor = checkNotNull(executor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,6 +130,15 @@ final class ResourceDeviceListener implements DeviceListener {
|
|||||||
executor.submit(() -> {
|
executor.submit(() -> {
|
||||||
adminService.registerResources(portPath);
|
adminService.registerResources(portPath);
|
||||||
|
|
||||||
|
queryBandwidth(device.id(), port.number())
|
||||||
|
.map(bw -> portPath.child(Bandwidth.class, bw.bps()))
|
||||||
|
.map(adminService::registerResources)
|
||||||
|
.ifPresent(success -> {
|
||||||
|
if (!success) {
|
||||||
|
log.error("Failed to register Bandwidth for {}", portPath.id());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// for VLAN IDs
|
// for VLAN IDs
|
||||||
Set<VlanId> vlans = queryVlanIds(device.id(), port.number());
|
Set<VlanId> vlans = queryVlanIds(device.id(), port.number());
|
||||||
if (!vlans.isEmpty()) {
|
if (!vlans.isEmpty()) {
|
||||||
@ -160,6 +178,30 @@ final class ResourceDeviceListener implements DeviceListener {
|
|||||||
executor.submit(() -> adminService.unregisterResources(resource));
|
executor.submit(() -> adminService.unregisterResources(resource));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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();
|
||||||
|
}
|
||||||
|
|
||||||
private Set<OchSignal> queryLambdas(DeviceId did, PortNumber port) {
|
private Set<OchSignal> queryLambdas(DeviceId did, PortNumber port) {
|
||||||
try {
|
try {
|
||||||
DriverHandler handler = driverService.createHandler(did);
|
DriverHandler handler = driverService.createHandler(did);
|
||||||
|
@ -0,0 +1,160 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016 Open Networking Laboratory
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.onosproject.net.newresource.impl;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static org.onosproject.net.newresource.Resource.continuous;
|
||||||
|
import static org.slf4j.LoggerFactory.getLogger;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
|
||||||
|
import org.onlab.util.Bandwidth;
|
||||||
|
import org.onosproject.net.ConnectPoint;
|
||||||
|
import org.onosproject.net.config.NetworkConfigEvent;
|
||||||
|
import org.onosproject.net.config.NetworkConfigListener;
|
||||||
|
import org.onosproject.net.config.NetworkConfigService;
|
||||||
|
import org.onosproject.net.newresource.BandwidthCapacity;
|
||||||
|
import org.onosproject.net.newresource.ResourceAdminService;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
|
import com.google.common.annotations.Beta;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
|
// TODO Consider merging this with ResourceDeviceListener.
|
||||||
|
/**
|
||||||
|
* Handler for NetworkConfiguration changes.
|
||||||
|
*/
|
||||||
|
@Beta
|
||||||
|
final class ResourceNetworkConfigListener implements NetworkConfigListener {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Config classes relevant to this listener.
|
||||||
|
*/
|
||||||
|
private static final Set<Class<?>> CONFIG_CLASSES = ImmutableSet.of(BandwidthCapacity.class);
|
||||||
|
|
||||||
|
private final Logger log = getLogger(getClass());
|
||||||
|
|
||||||
|
private final ResourceAdminService adminService;
|
||||||
|
private final NetworkConfigService cfgService;
|
||||||
|
private final ExecutorService executor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an instance of listener.
|
||||||
|
*
|
||||||
|
* @param adminService {@link ResourceAdminService}
|
||||||
|
* @param cfgService {@link NetworkConfigService}
|
||||||
|
* @param executor Executor to use.
|
||||||
|
*/
|
||||||
|
ResourceNetworkConfigListener(ResourceAdminService adminService, NetworkConfigService cfgService,
|
||||||
|
ExecutorService executor) {
|
||||||
|
this.adminService = checkNotNull(adminService);
|
||||||
|
this.cfgService = checkNotNull(cfgService);
|
||||||
|
this.executor = checkNotNull(executor);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isRelevant(NetworkConfigEvent event) {
|
||||||
|
return CONFIG_CLASSES.contains(event.configClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void event(NetworkConfigEvent event) {
|
||||||
|
if (event.configClass() == BandwidthCapacity.class) {
|
||||||
|
executor.submit(() -> {
|
||||||
|
try {
|
||||||
|
handleBandwidthCapacity(event);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Exception handling BandwidthCapacity", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleBandwidthCapacity(NetworkConfigEvent event) {
|
||||||
|
checkArgument(event.configClass() == BandwidthCapacity.class);
|
||||||
|
|
||||||
|
ConnectPoint cp = (ConnectPoint) event.subject();
|
||||||
|
BandwidthCapacity bwCapacity = cfgService.getConfig(cp, BandwidthCapacity.class);
|
||||||
|
|
||||||
|
switch (event.type()) {
|
||||||
|
case CONFIG_ADDED:
|
||||||
|
if (!adminService.registerResources(continuous(bwCapacity.capacity().bps(),
|
||||||
|
cp.deviceId(),
|
||||||
|
cp.port(), Bandwidth.class))) {
|
||||||
|
log.info("Failed to register Bandwidth for {}, attempting update", cp);
|
||||||
|
|
||||||
|
// Bandwidth based on port speed, was probably already registered.
|
||||||
|
// need to update to the valued based on configuration
|
||||||
|
|
||||||
|
if (!updateRegistration(cp, bwCapacity)) {
|
||||||
|
log.warn("Failed to update Bandwidth for {}", cp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CONFIG_UPDATED:
|
||||||
|
if (!updateRegistration(cp, bwCapacity)) {
|
||||||
|
log.warn("Failed to update Bandwidth for {}", cp);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CONFIG_REMOVED:
|
||||||
|
// FIXME Following should be an update to the value based on port speed
|
||||||
|
if (!adminService.unregisterResources(continuous(0,
|
||||||
|
cp.deviceId(),
|
||||||
|
cp.port(),
|
||||||
|
Bandwidth.class))) {
|
||||||
|
log.warn("Failed to unregister Bandwidth for {}", cp);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CONFIG_REGISTERED:
|
||||||
|
case CONFIG_UNREGISTERED:
|
||||||
|
// no-op
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean updateRegistration(ConnectPoint cp, BandwidthCapacity bwCapacity) {
|
||||||
|
// FIXME workaround until replace/update semantics become available
|
||||||
|
// this potentially blows up existing registration
|
||||||
|
// or end up as no-op
|
||||||
|
//
|
||||||
|
// Current code end up in situation like below:
|
||||||
|
// PortNumber: 2
|
||||||
|
// MplsLabel: [[16‥240)]
|
||||||
|
// VlanId: [[0‥4095)]
|
||||||
|
// Bandwidth: 2000000.000000
|
||||||
|
// Bandwidth: 20000000.000000
|
||||||
|
//
|
||||||
|
// but both unregisterResources(..) and registerResources(..)
|
||||||
|
// returns true (success)
|
||||||
|
|
||||||
|
if (!adminService.unregisterResources(continuous(0, cp.deviceId(), cp.port(), Bandwidth.class))) {
|
||||||
|
log.warn("unregisterResources for {} failed", cp);
|
||||||
|
}
|
||||||
|
return adminService.registerResources(continuous(bwCapacity.capacity().bps(),
|
||||||
|
cp.deviceId(),
|
||||||
|
cp.port(),
|
||||||
|
Bandwidth.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -16,20 +16,31 @@
|
|||||||
package org.onosproject.net.newresource.impl;
|
package org.onosproject.net.newresource.impl;
|
||||||
|
|
||||||
import com.google.common.annotations.Beta;
|
import com.google.common.annotations.Beta;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
import org.apache.felix.scr.annotations.Activate;
|
import org.apache.felix.scr.annotations.Activate;
|
||||||
import org.apache.felix.scr.annotations.Component;
|
import org.apache.felix.scr.annotations.Component;
|
||||||
import org.apache.felix.scr.annotations.Deactivate;
|
import org.apache.felix.scr.annotations.Deactivate;
|
||||||
import org.apache.felix.scr.annotations.Reference;
|
import org.apache.felix.scr.annotations.Reference;
|
||||||
import org.apache.felix.scr.annotations.ReferenceCardinality;
|
import org.apache.felix.scr.annotations.ReferenceCardinality;
|
||||||
|
import org.onosproject.net.ConnectPoint;
|
||||||
|
import org.onosproject.net.config.ConfigFactory;
|
||||||
|
import org.onosproject.net.config.NetworkConfigListener;
|
||||||
|
import org.onosproject.net.config.NetworkConfigRegistry;
|
||||||
import org.onosproject.net.device.DeviceListener;
|
import org.onosproject.net.device.DeviceListener;
|
||||||
import org.onosproject.net.device.DeviceService;
|
import org.onosproject.net.device.DeviceService;
|
||||||
import org.onosproject.net.driver.DriverService;
|
import org.onosproject.net.driver.DriverService;
|
||||||
|
import org.onosproject.net.newresource.BandwidthCapacity;
|
||||||
import org.onosproject.net.newresource.ResourceAdminService;
|
import org.onosproject.net.newresource.ResourceAdminService;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
import static org.onlab.util.Tools.groupedThreads;
|
import static org.onlab.util.Tools.groupedThreads;
|
||||||
|
import static org.onosproject.net.config.basics.SubjectFactories.CONNECT_POINT_SUBJECT_FACTORY;
|
||||||
|
import static org.slf4j.LoggerFactory.getLogger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class registering resources when they are detected.
|
* A class registering resources when they are detected.
|
||||||
@ -47,19 +58,52 @@ public final class ResourceRegistrar {
|
|||||||
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
|
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
|
||||||
protected DeviceService deviceService;
|
protected DeviceService deviceService;
|
||||||
|
|
||||||
|
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
|
||||||
|
protected NetworkConfigRegistry cfgRegistry;
|
||||||
|
|
||||||
|
private final Logger log = getLogger(getClass());
|
||||||
|
|
||||||
|
private final List<ConfigFactory<?, ?>> factories = ImmutableList.of(
|
||||||
|
new ConfigFactory<ConnectPoint, BandwidthCapacity>(CONNECT_POINT_SUBJECT_FACTORY,
|
||||||
|
BandwidthCapacity.class, BandwidthCapacity.CONFIG_KEY) {
|
||||||
|
@Override
|
||||||
|
public BandwidthCapacity createConfig() {
|
||||||
|
return new BandwidthCapacity();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
private DeviceListener deviceListener;
|
private DeviceListener deviceListener;
|
||||||
|
|
||||||
private final ExecutorService executor =
|
private final ExecutorService executor =
|
||||||
Executors.newSingleThreadExecutor(groupedThreads("onos/resource", "registrar"));
|
Executors.newSingleThreadExecutor(groupedThreads("onos/resource", "registrar"));
|
||||||
|
|
||||||
|
private NetworkConfigListener cfgListener;
|
||||||
|
|
||||||
@Activate
|
@Activate
|
||||||
public void activate() {
|
public void activate() {
|
||||||
deviceListener = new ResourceDeviceListener(adminService, deviceService, driverService, executor);
|
factories.forEach(cfgRegistry::registerConfigFactory);
|
||||||
|
|
||||||
|
cfgListener = new ResourceNetworkConfigListener(adminService, cfgRegistry, executor);
|
||||||
|
cfgRegistry.addListener(cfgListener);
|
||||||
|
|
||||||
|
deviceListener = new ResourceDeviceListener(adminService, deviceService, driverService, cfgRegistry, executor);
|
||||||
deviceService.addListener(deviceListener);
|
deviceService.addListener(deviceListener);
|
||||||
|
|
||||||
|
// TODO Attempt initial registration of existing resources?
|
||||||
|
|
||||||
|
log.info("Started");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deactivate
|
@Deactivate
|
||||||
public void deactivate() {
|
public void deactivate() {
|
||||||
deviceService.removeListener(deviceListener);
|
deviceService.removeListener(deviceListener);
|
||||||
|
cfgRegistry.removeListener(cfgListener);
|
||||||
|
|
||||||
executor.shutdownNow();
|
executor.shutdownNow();
|
||||||
|
|
||||||
|
factories.forEach(cfgRegistry::unregisterConfigFactory);
|
||||||
|
|
||||||
|
log.info("Stopped");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
14
tools/package/config/samples/network-cfg-bandwidth.json
Normal file
14
tools/package/config/samples/network-cfg-bandwidth.json
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"ports": {
|
||||||
|
"of:0000000000000002/1": {
|
||||||
|
"bandwidthCapacity": {
|
||||||
|
"capacityMbps": 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"of:0000000000000002/2": {
|
||||||
|
"bandwidthCapacity": {
|
||||||
|
"capacityMbps": 2.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user