Marc De Leenheer
Committed by Gerrit Code Review

Static optical madness. Fix in device resource store. Javadoc.

Change-Id: Iaba6b62094b3d2023f352d52037c6d1535c31b88
......@@ -378,8 +378,10 @@ public class OpticalPathProvisioner {
LinkResourceAllocations lra = linkResourceService.getAllocations(intent.id());
if (intent instanceof OpticalConnectivityIntent) {
deviceResourceService.releasePorts(intent.id());
linkResourceService.releaseResources(lra);
} else if (intent instanceof OpticalCircuitIntent) {
if (lra != null) {
linkResourceService.releaseResources(lra);
}
} else if (intent instanceof OpticalCircuitIntent) {
deviceResourceService.releasePorts(intent.id());
deviceResourceService.releaseMapping(intent.id());
if (lra != null) {
......
......@@ -17,6 +17,7 @@ package org.onosproject.net;
import com.google.common.base.MoreObjects;
import org.onlab.util.Frequency;
import org.onosproject.net.resource.link.LambdaResourceAllocation;
import java.util.Objects;
......@@ -34,6 +35,9 @@ public class OchSignal implements Lambda {
public static final Frequency CENTER_FREQUENCY = Frequency.ofTHz(193.1);
public static final Frequency FLEX_GRID_SLOT = Frequency.ofGHz(12.5);
private static final GridType DEFAULT_OCH_GRIDTYPE = GridType.DWDM;
private static final ChannelSpacing DEFAULT_CHANNEL_SPACING = ChannelSpacing.CHL_50GHZ;
private final GridType gridType;
private final ChannelSpacing channelSpacing;
......@@ -63,6 +67,33 @@ public class OchSignal implements Lambda {
}
/**
* Create OCh signal from lambda resource allocation.
*
* @param alloc lambda resource allocation
* @param maxFrequency maximum frequency
* @param grid grid spacing frequency
*/
public OchSignal(LambdaResourceAllocation alloc, Frequency maxFrequency, Frequency grid) {
int channel = alloc.lambda().toInt();
// Calculate center frequency
Frequency centerFrequency = maxFrequency.subtract(grid.multiply(channel - 1));
this.gridType = DEFAULT_OCH_GRIDTYPE;
this.channelSpacing = DEFAULT_CHANNEL_SPACING;
this.spacingMultiplier = (int) (centerFrequency.subtract(OchSignal.CENTER_FREQUENCY).asHz() / grid.asHz());
this.slotGranularity = (int) Math.round((double) grid.asHz() / ChannelSpacing.CHL_12P5GHZ.frequency().asHz());
}
public OchSignal(Frequency centerFrequency, ChannelSpacing channelSpacing, int slotGranularity) {
this.gridType = DEFAULT_OCH_GRIDTYPE;
this.channelSpacing = channelSpacing;
this.spacingMultiplier = (int) Math.round((double) centerFrequency.
subtract(OchSignal.CENTER_FREQUENCY).asHz() / channelSpacing().frequency().asHz());
this.slotGranularity = slotGranularity;
}
/**
* Returns grid type.
*
* @return grid type
......
......@@ -165,9 +165,9 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu
* Checks if current allocations on given resource can satisfy request.
* If the resource is null, return true.
*
* @param request
* @param resource
* @return
* @param request the intent making the request
* @param resource the resource on which to map the intent
* @return true if the resource can accept the request, false otherwise
*/
private boolean isAvailable(Intent request, IntentId resource) {
if (resource == null) {
......
......@@ -27,10 +27,8 @@ import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onlab.util.Frequency;
import org.onosproject.net.AnnotationKeys;
import org.onosproject.net.ChannelSpacing;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.GridType;
import org.onosproject.net.Link;
import org.onosproject.net.OchPort;
import org.onosproject.net.OchSignal;
......@@ -73,9 +71,6 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical
protected static final Logger log = LoggerFactory.getLogger(OpticalConnectivityIntentCompiler.class);
private static final GridType DEFAULT_OCH_GRIDTYPE = GridType.DWDM;
private static final ChannelSpacing DEFAULT_CHANNEL_SPACING = ChannelSpacing.CHL_50GHZ;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected IntentExtensionService intentManager;
......@@ -127,24 +122,31 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical
for (Path path : paths) {
// Static or dynamic lambda allocation
LambdaResourceAllocation lambdaAlloc;
String staticLambda = srcPort.annotations().value(AnnotationKeys.STATIC_LAMBDA);
OchPort srcOchPort = (OchPort) srcPort;
OchPort dstOchPort = (OchPort) dstPort;
OchSignal ochSignal;
// FIXME: need to actually reserve the lambda for static lambda's
if (staticLambda != null) {
// FIXME: need to actually reserve the lambda
lambdaAlloc = new LambdaResourceAllocation(LambdaResource.valueOf(Integer.parseInt(staticLambda)));
ochSignal = new OchSignal(Frequency.ofHz(Long.valueOf(staticLambda)),
srcOchPort.lambda().channelSpacing(),
srcOchPort.lambda().slotGranularity());
} else if (!srcOchPort.isTunable() || !dstOchPort.isTunable()) {
// FIXME: also check OCh port
ochSignal = srcOchPort.lambda();
} else {
// Request and reserve lambda on path
LinkResourceAllocations linkAllocs = assignWavelength(intent, path);
if (linkAllocs == null) {
continue;
}
lambdaAlloc = getWavelength(path, linkAllocs);
LambdaResourceAllocation lambdaAlloc = getWavelength(path, linkAllocs);
OmsPort omsPort = (OmsPort) deviceService.getPort(path.src().deviceId(), path.src().port());
ochSignal = new OchSignal(lambdaAlloc, omsPort.maxFrequency(), omsPort.grid());
}
OmsPort omsPort = (OmsPort) deviceService.getPort(path.src().deviceId(), path.src().port());
// Create installable optical path intent
OchSignal ochSignal = getOchSignal(lambdaAlloc, omsPort.maxFrequency(), omsPort.grid());
// Only support fixed grid for now
OchSignalType signalType = OchSignalType.FIXED_GRID;
......@@ -239,29 +241,6 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical
return true;
}
/**
* Convert lambda resource allocation in OCh signal.
*
* @param alloc lambda resource allocation
* @param maxFrequency maximum frequency
* @param grid grid spacing frequency
* @return OCh signal
*/
private OchSignal getOchSignal(LambdaResourceAllocation alloc, Frequency maxFrequency, Frequency grid) {
int channel = alloc.lambda().toInt();
// Calculate center frequency
Frequency centerFrequency = maxFrequency.subtract(grid.multiply(channel - 1));
// Build OCh signal object
int spacingMultiplier = (int) (centerFrequency.subtract(OchSignal.CENTER_FREQUENCY).asHz() / grid.asHz());
int slotGranularity = (int) (grid.asHz() / ChannelSpacing.CHL_12P5GHZ.frequency().asHz());
OchSignal ochSignal = new OchSignal(DEFAULT_OCH_GRIDTYPE, DEFAULT_CHANNEL_SPACING,
spacingMultiplier, slotGranularity);
return ochSignal;
}
private ConnectPoint staticPort(ConnectPoint connectPoint) {
Port port = deviceService.getPort(connectPoint.deviceId(), connectPoint.port());
......
......@@ -167,7 +167,7 @@ public class ConsistentDeviceResourceStore implements DeviceResourceStore {
public Set<IntentId> getMapping(IntentId intentId) {
Versioned<Set<IntentId>> result = intentMapping.get(intentId);
if (result == null) {
if (result != null) {
return result.value();
}
......@@ -178,7 +178,6 @@ public class ConsistentDeviceResourceStore implements DeviceResourceStore {
public boolean allocateMapping(IntentId keyIntentId, IntentId valIntentId) {
Versioned<Set<IntentId>> versionedIntents = intentMapping.get(keyIntentId);
if (versionedIntents == null) {
Set<IntentId> newSet = new HashSet<>();
newSet.add(valIntentId);
......@@ -216,6 +215,7 @@ public class ConsistentDeviceResourceStore implements DeviceResourceStore {
for (Port port : ports) {
portAllocs.remove(port);
}
tx.commit();
} catch (Exception e) {
log.error("Exception thrown, rolling back", e);
tx.abort();
......
......@@ -235,7 +235,11 @@ class ConfigProvider implements DeviceProvider, LinkProvider, HostProvider {
port = portNumber(node.path("port").asLong(0));
}
checkNotNull(port);
if (port == null) {
log.error("Cannot find port given in node {}", node);
return null;
}
String portName = Strings.emptyToNull(port.name());
SparseAnnotations annotations = null;
if (portName != null) {
......