mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-23 21:31:00 +02:00
Misc device/optical config features:
o devices and optical ports are updated with network configs o refactored AllowedEntity checks in DeviceManager o "basic" -> "optical" for OpticalPort config key o Device and OpticalPort operators can create descriptions Change-Id: I59edc368f3a8ff931954b174d4a898f6b4add5d5
This commit is contained in:
parent
e090a42276
commit
d0ab3c02ef
@ -84,7 +84,7 @@ public class BasicNetworkConfigs {
|
|||||||
},
|
},
|
||||||
new ConfigFactory<ConnectPoint, OpticalPortConfig>(CONNECT_POINT_SUBJECT_FACTORY,
|
new ConfigFactory<ConnectPoint, OpticalPortConfig>(CONNECT_POINT_SUBJECT_FACTORY,
|
||||||
OpticalPortConfig.class,
|
OpticalPortConfig.class,
|
||||||
"basic") {
|
"optical") {
|
||||||
@Override
|
@Override
|
||||||
public OpticalPortConfig createConfig() {
|
public OpticalPortConfig createConfig() {
|
||||||
return new OpticalPortConfig();
|
return new OpticalPortConfig();
|
||||||
|
|||||||
@ -16,6 +16,7 @@
|
|||||||
package org.onosproject.net.device.impl;
|
package org.onosproject.net.device.impl;
|
||||||
|
|
||||||
import static org.slf4j.LoggerFactory.getLogger;
|
import static org.slf4j.LoggerFactory.getLogger;
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import org.onosproject.net.config.ConfigOperator;
|
import org.onosproject.net.config.ConfigOperator;
|
||||||
import org.onosproject.net.config.basics.BasicDeviceConfig;
|
import org.onosproject.net.config.basics.BasicDeviceConfig;
|
||||||
@ -93,4 +94,12 @@ public final class BasicDeviceOperator implements ConfigOperator {
|
|||||||
DefaultAnnotations newAnnotations = newBuilder.build();
|
DefaultAnnotations newAnnotations = newBuilder.build();
|
||||||
return DefaultAnnotations.union(an, newAnnotations);
|
return DefaultAnnotations.union(an, newAnnotations);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static DeviceDescription descriptionOf(Device device) {
|
||||||
|
checkNotNull(device, "Must supply non-null Device");
|
||||||
|
return new DefaultDeviceDescription(device.id().uri(), device.type(),
|
||||||
|
device.manufacturer(), device.hwVersion(),
|
||||||
|
device.swVersion(), device.serialNumber(),
|
||||||
|
device.chassisId(), (SparseAnnotations) device.annotations());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,11 +31,13 @@ import org.onosproject.net.config.NetworkConfigEvent;
|
|||||||
import org.onosproject.net.config.NetworkConfigListener;
|
import org.onosproject.net.config.NetworkConfigListener;
|
||||||
import org.onosproject.net.config.NetworkConfigService;
|
import org.onosproject.net.config.NetworkConfigService;
|
||||||
import org.onosproject.net.config.basics.BasicDeviceConfig;
|
import org.onosproject.net.config.basics.BasicDeviceConfig;
|
||||||
|
import org.onosproject.net.config.basics.OpticalPortConfig;
|
||||||
import org.onosproject.mastership.MastershipEvent;
|
import org.onosproject.mastership.MastershipEvent;
|
||||||
import org.onosproject.mastership.MastershipListener;
|
import org.onosproject.mastership.MastershipListener;
|
||||||
import org.onosproject.mastership.MastershipService;
|
import org.onosproject.mastership.MastershipService;
|
||||||
import org.onosproject.mastership.MastershipTerm;
|
import org.onosproject.mastership.MastershipTerm;
|
||||||
import org.onosproject.mastership.MastershipTermService;
|
import org.onosproject.mastership.MastershipTermService;
|
||||||
|
import org.onosproject.net.ConnectPoint;
|
||||||
import org.onosproject.net.Device;
|
import org.onosproject.net.Device;
|
||||||
import org.onosproject.net.Device.Type;
|
import org.onosproject.net.Device.Type;
|
||||||
import org.onosproject.net.DeviceId;
|
import org.onosproject.net.DeviceId;
|
||||||
@ -64,13 +66,13 @@ import java.util.HashSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
|
||||||
import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor;
|
import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor;
|
||||||
import static org.onlab.util.Tools.groupedThreads;
|
import static org.onlab.util.Tools.groupedThreads;
|
||||||
import static org.onosproject.net.MastershipRole.*;
|
import static org.onosproject.net.MastershipRole.*;
|
||||||
@ -78,7 +80,6 @@ import static org.onosproject.security.AppGuard.checkPermission;
|
|||||||
import static org.slf4j.LoggerFactory.getLogger;
|
import static org.slf4j.LoggerFactory.getLogger;
|
||||||
import static org.onosproject.security.AppPermission.Type.*;
|
import static org.onosproject.security.AppPermission.Type.*;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides implementation of the device SB & NB APIs.
|
* Provides implementation of the device SB & NB APIs.
|
||||||
*/
|
*/
|
||||||
@ -92,6 +93,7 @@ public class DeviceManager
|
|||||||
private static final String PORT_NUMBER_NULL = "Port number cannot be null";
|
private static final String PORT_NUMBER_NULL = "Port number cannot be null";
|
||||||
private static final String DEVICE_DESCRIPTION_NULL = "Device description cannot be null";
|
private static final String DEVICE_DESCRIPTION_NULL = "Device description cannot be null";
|
||||||
private static final String PORT_DESCRIPTION_NULL = "Port description cannot be null";
|
private static final String PORT_DESCRIPTION_NULL = "Port description cannot be null";
|
||||||
|
private static final String PORT_DESC_LIST_NULL = "Port description list cannot be null";
|
||||||
|
|
||||||
private final Logger log = getLogger(getClass());
|
private final Logger log = getLogger(getClass());
|
||||||
|
|
||||||
@ -265,8 +267,7 @@ public class DeviceManager
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("{} is reachable but did not have a valid role, reasserting",
|
log.info("{} is reachable but did not have a valid role, reasserting", deviceId);
|
||||||
deviceId);
|
|
||||||
|
|
||||||
// isReachable but was not MASTER or STANDBY, get a role and apply
|
// isReachable but was not MASTER or STANDBY, get a role and apply
|
||||||
// Note: NONE triggers request to MastershipService
|
// Note: NONE triggers request to MastershipService
|
||||||
@ -309,16 +310,20 @@ public class DeviceManager
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deviceConnected(DeviceId deviceId,
|
public void deviceConnected(DeviceId deviceId,
|
||||||
DeviceDescription deviceDescription) {
|
DeviceDescription deviceDescription) {
|
||||||
checkNotNull(deviceId, DEVICE_ID_NULL);
|
checkNotNull(deviceId, DEVICE_ID_NULL);
|
||||||
checkNotNull(deviceDescription, DEVICE_DESCRIPTION_NULL);
|
checkNotNull(deviceDescription, DEVICE_DESCRIPTION_NULL);
|
||||||
checkValidity();
|
checkValidity();
|
||||||
deviceDescription = validateDevice(deviceDescription, deviceId);
|
|
||||||
|
|
||||||
// Establish my Role
|
BasicDeviceConfig cfg = networkConfigService.getConfig(deviceId, BasicDeviceConfig.class);
|
||||||
|
if (!isAllowed(cfg)) {
|
||||||
|
log.warn("Device {} is not allowed", deviceId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Generate updated description and establish my Role
|
||||||
|
deviceDescription = BasicDeviceOperator.combine(cfg, deviceDescription);
|
||||||
Futures.getUnchecked(mastershipService.requestRoleFor(deviceId)
|
Futures.getUnchecked(mastershipService.requestRoleFor(deviceId)
|
||||||
.thenAccept(role -> {
|
.thenAccept(role -> {
|
||||||
log.info("Local role is {} for {}", role, deviceId);
|
log.info("Local role is {} for {}", role, deviceId);
|
||||||
@ -327,22 +332,13 @@ public class DeviceManager
|
|||||||
|
|
||||||
DeviceEvent event = store.createOrUpdateDevice(provider().id(), deviceId,
|
DeviceEvent event = store.createOrUpdateDevice(provider().id(), deviceId,
|
||||||
deviceDescription);
|
deviceDescription);
|
||||||
|
log.info("Device {} connected", deviceId);
|
||||||
if (event != null) {
|
if (event != null) {
|
||||||
log.trace("event: {} {}", event.type(), event);
|
log.trace("event: {} {}", event.type(), event);
|
||||||
post(event);
|
post(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns a DeviceDescription made from the union of the BasicDeviceConfig
|
|
||||||
// annotations if it exists
|
|
||||||
private DeviceDescription validateDevice(DeviceDescription deviceDescription, DeviceId deviceId) {
|
|
||||||
BasicDeviceConfig cfg = networkConfigService.getConfig(deviceId, BasicDeviceConfig.class);
|
|
||||||
checkState(cfg == null || cfg.isAllowed(), "Device " + deviceId + " is not allowed");
|
|
||||||
log.info("Device {} connected", deviceId);
|
|
||||||
|
|
||||||
return BasicDeviceOperator.combine(cfg, deviceDescription);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deviceDisconnected(DeviceId deviceId) {
|
public void deviceDisconnected(DeviceId deviceId) {
|
||||||
checkNotNull(deviceId, DEVICE_ID_NULL);
|
checkNotNull(deviceId, DEVICE_ID_NULL);
|
||||||
@ -402,8 +398,7 @@ public class DeviceManager
|
|||||||
public void updatePorts(DeviceId deviceId,
|
public void updatePorts(DeviceId deviceId,
|
||||||
List<PortDescription> portDescriptions) {
|
List<PortDescription> portDescriptions) {
|
||||||
checkNotNull(deviceId, DEVICE_ID_NULL);
|
checkNotNull(deviceId, DEVICE_ID_NULL);
|
||||||
checkNotNull(portDescriptions,
|
checkNotNull(portDescriptions, PORT_DESC_LIST_NULL);
|
||||||
"Port descriptions list cannot be null");
|
|
||||||
checkValidity();
|
checkValidity();
|
||||||
if (!mastershipService.isLocalMaster(deviceId)) {
|
if (!mastershipService.isLocalMaster(deviceId)) {
|
||||||
// Never been a master for this device
|
// Never been a master for this device
|
||||||
@ -411,7 +406,9 @@ public class DeviceManager
|
|||||||
log.trace("Ignoring {} port updates on standby node. {}", deviceId, portDescriptions);
|
log.trace("Ignoring {} port updates on standby node. {}", deviceId, portDescriptions);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
portDescriptions = portDescriptions.stream()
|
||||||
|
.map(e -> consolidate(deviceId, e))
|
||||||
|
.collect(Collectors.toList());
|
||||||
List<DeviceEvent> events = store.updatePorts(this.provider().id(),
|
List<DeviceEvent> events = store.updatePorts(this.provider().id(),
|
||||||
deviceId, portDescriptions);
|
deviceId, portDescriptions);
|
||||||
for (DeviceEvent event : events) {
|
for (DeviceEvent event : events) {
|
||||||
@ -433,16 +430,28 @@ public class DeviceManager
|
|||||||
portDescription);
|
portDescription);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
portDescription = consolidate(deviceId, portDescription);
|
||||||
final DeviceEvent event = store.updatePortStatus(this.provider().id(),
|
final DeviceEvent event = store.updatePortStatus(this.provider().id(),
|
||||||
deviceId, portDescription);
|
deviceId, portDescription);
|
||||||
if (event != null) {
|
if (event != null) {
|
||||||
log.info("Device {} port {} status changed", deviceId, event
|
log.info("Device {} port {} status changed", deviceId, event.port().number());
|
||||||
.port().number());
|
|
||||||
post(event);
|
post(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// merges the appropriate PortConfig with the description.
|
||||||
|
private PortDescription consolidate(DeviceId did, PortDescription desc) {
|
||||||
|
switch (desc.type()) {
|
||||||
|
case COPPER:
|
||||||
|
case VIRTUAL:
|
||||||
|
return desc;
|
||||||
|
default:
|
||||||
|
OpticalPortConfig opc = networkConfigService.getConfig(
|
||||||
|
new ConnectPoint(did, desc.portNumber()), OpticalPortConfig.class);
|
||||||
|
return OpticalPortOperator.combine(opc, desc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void receivedRoleReply(DeviceId deviceId, MastershipRole requested,
|
public void receivedRoleReply(DeviceId deviceId, MastershipRole requested,
|
||||||
MastershipRole response) {
|
MastershipRole response) {
|
||||||
@ -498,6 +507,11 @@ public class DeviceManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// by default allowed, otherwise check flag
|
||||||
|
private boolean isAllowed(BasicDeviceConfig cfg) {
|
||||||
|
return (cfg == null || cfg.isAllowed());
|
||||||
|
}
|
||||||
|
|
||||||
// Applies the specified role to the device; ignores NONE
|
// Applies the specified role to the device; ignores NONE
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -617,7 +631,6 @@ public class DeviceManager
|
|||||||
myNextRole = NONE;
|
myNextRole = NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
final boolean isReachable = isReachable(did);
|
final boolean isReachable = isReachable(did);
|
||||||
if (!isReachable) {
|
if (!isReachable) {
|
||||||
// device is not connected to this node
|
// device is not connected to this node
|
||||||
@ -695,23 +708,54 @@ public class DeviceManager
|
|||||||
private class InternalNetworkConfigListener implements NetworkConfigListener {
|
private class InternalNetworkConfigListener implements NetworkConfigListener {
|
||||||
@Override
|
@Override
|
||||||
public boolean isRelevant(NetworkConfigEvent event) {
|
public boolean isRelevant(NetworkConfigEvent event) {
|
||||||
return (event.type() == NetworkConfigEvent.Type.CONFIG_ADDED ||
|
return (event.type() == NetworkConfigEvent.Type.CONFIG_ADDED
|
||||||
event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED)
|
|| event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED)
|
||||||
&& event.configClass().equals(BasicDeviceConfig.class);
|
&& (event.configClass().equals(BasicDeviceConfig.class)
|
||||||
|
|| event.configClass().equals(OpticalPortConfig.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void event(NetworkConfigEvent event) {
|
public void event(NetworkConfigEvent event) {
|
||||||
log.info("Detected Device network config event {}", event.type());
|
DeviceEvent de = null;
|
||||||
kickOutBadDevice(((DeviceId) event.subject()));
|
if (event.configClass().equals(BasicDeviceConfig.class)) {
|
||||||
}
|
log.info("Detected Device network config event {}", event.type());
|
||||||
}
|
DeviceId did = (DeviceId) event.subject();
|
||||||
|
BasicDeviceConfig cfg = networkConfigService.getConfig(did, BasicDeviceConfig.class);
|
||||||
|
|
||||||
// checks if the specified device is allowed by the BasicDeviceConfig
|
if (!isAllowed(cfg)) {
|
||||||
// and if not, removes it
|
kickOutBadDevice(did);
|
||||||
private void kickOutBadDevice(DeviceId deviceId) {
|
} else {
|
||||||
BasicDeviceConfig cfg = networkConfigService.getConfig(deviceId, BasicDeviceConfig.class);
|
Device dev = getDevice(did);
|
||||||
if (!cfg.isAllowed()) {
|
DeviceDescription desc = (dev == null) ? null : BasicDeviceOperator.descriptionOf(dev);
|
||||||
|
desc = BasicDeviceOperator.combine(cfg, desc);
|
||||||
|
if (getProvider(did) != null) {
|
||||||
|
de = store.createOrUpdateDevice(getProvider(did).id(), did, desc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (event.configClass().equals(OpticalPortConfig.class)) {
|
||||||
|
ConnectPoint cpt = (ConnectPoint) event.subject();
|
||||||
|
DeviceId did = cpt.deviceId();
|
||||||
|
Port dpt = getPort(did, cpt.port());
|
||||||
|
|
||||||
|
if (dpt != null) {
|
||||||
|
OpticalPortConfig opc = networkConfigService.getConfig(cpt, OpticalPortConfig.class);
|
||||||
|
PortDescription desc = OpticalPortOperator.descriptionOf(dpt);
|
||||||
|
desc = OpticalPortOperator.combine(opc, desc);
|
||||||
|
if (getProvider(did) != null) {
|
||||||
|
de = store.updatePortStatus(getProvider(did).id(), did, desc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (de != null) {
|
||||||
|
post(de);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// checks if the specified device is allowed by the BasicDeviceConfig
|
||||||
|
// and if not, removes it
|
||||||
|
private void kickOutBadDevice(DeviceId deviceId) {
|
||||||
Device badDevice = getDevice(deviceId);
|
Device badDevice = getDevice(deviceId);
|
||||||
if (badDevice != null) {
|
if (badDevice != null) {
|
||||||
removeDevice(deviceId);
|
removeDevice(deviceId);
|
||||||
|
|||||||
@ -16,11 +16,16 @@
|
|||||||
package org.onosproject.net.device.impl;
|
package org.onosproject.net.device.impl;
|
||||||
|
|
||||||
import static org.slf4j.LoggerFactory.getLogger;
|
import static org.slf4j.LoggerFactory.getLogger;
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import org.onosproject.net.config.ConfigOperator;
|
import org.onosproject.net.config.ConfigOperator;
|
||||||
import org.onosproject.net.config.basics.OpticalPortConfig;
|
import org.onosproject.net.config.basics.OpticalPortConfig;
|
||||||
import org.onosproject.net.AnnotationKeys;
|
import org.onosproject.net.AnnotationKeys;
|
||||||
import org.onosproject.net.DefaultAnnotations;
|
import org.onosproject.net.DefaultAnnotations;
|
||||||
|
import org.onosproject.net.OchPort;
|
||||||
|
import org.onosproject.net.OduCltPort;
|
||||||
|
import org.onosproject.net.OmsPort;
|
||||||
|
import org.onosproject.net.Port;
|
||||||
import org.onosproject.net.PortNumber;
|
import org.onosproject.net.PortNumber;
|
||||||
import org.onosproject.net.SparseAnnotations;
|
import org.onosproject.net.SparseAnnotations;
|
||||||
import org.onosproject.net.device.DefaultPortDescription;
|
import org.onosproject.net.device.DefaultPortDescription;
|
||||||
@ -137,4 +142,32 @@ public final class OpticalPortOperator implements ConfigOperator {
|
|||||||
}
|
}
|
||||||
return DefaultAnnotations.union(an, b.build());
|
return DefaultAnnotations.union(an, b.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a description built from an existing port.
|
||||||
|
*
|
||||||
|
* @param port the device port
|
||||||
|
* @return a PortDescription based on the port
|
||||||
|
*/
|
||||||
|
public static PortDescription descriptionOf(Port port) {
|
||||||
|
checkNotNull(port, "Must supply non-null Port");
|
||||||
|
final PortNumber ptn = port.number();
|
||||||
|
final boolean isup = port.isEnabled();
|
||||||
|
final SparseAnnotations an = (SparseAnnotations) port.annotations();
|
||||||
|
switch (port.type()) {
|
||||||
|
case OMS:
|
||||||
|
OmsPort oms = (OmsPort) port;
|
||||||
|
return new OmsPortDescription(ptn, isup, oms.minFrequency(),
|
||||||
|
oms.maxFrequency(), oms.grid(), an);
|
||||||
|
case OCH:
|
||||||
|
OchPort och = (OchPort) port;
|
||||||
|
return new OchPortDescription(ptn, isup, och.signalType(),
|
||||||
|
och.isTunable(), och.lambda(), an);
|
||||||
|
case ODUCLT:
|
||||||
|
OduCltPort odu = (OduCltPort) port;
|
||||||
|
return new OduCltPortDescription(ptn, isup, odu.signalType(), an);
|
||||||
|
default:
|
||||||
|
return new DefaultPortDescription(ptn, isup, port.type(), port.portSpeed(), an);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user