Rimon Ashkenazy
Committed by Gerrit Code Review

Add Optical ODU cross-connect Intent

Create a new intent: OpticalOduIntent in the OTN Topology.
 - This intent finds a path of OTU links, and
 - Allocates TributarySlots resources on the OTU ports (in the path)
 - also add a utility for converting various SignalTypes to
   OduSignalType, and to build the OduSignalId.

Note: this patch follows the example given in patch
https://gerrit.onosproject.org/#/c/7321 of
separate resource search from resource allocation.

Change-Id: Id9808f61aebb80a21481f3882aff23b236b68078
......@@ -20,6 +20,7 @@ import org.apache.karaf.shell.commands.Command;
import org.apache.karaf.shell.commands.Option;
import org.onosproject.net.CltSignalType;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.Device;
import org.onosproject.net.OchPort;
import org.onosproject.net.OduCltPort;
import org.onosproject.net.DeviceId;
......@@ -30,6 +31,7 @@ import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentService;
import org.onosproject.net.intent.OpticalCircuitIntent;
import org.onosproject.net.intent.OpticalConnectivityIntent;
import org.onosproject.net.intent.OpticalOduIntent;
import java.util.List;
......@@ -96,27 +98,52 @@ public class AddOpticalIntentCommand extends ConnectivityIntentCommand {
Port dstPort = deviceService.getPort(egress.deviceId(), egress.port());
Intent intent;
// FIXME: Hardcoded signal types
if (srcPort instanceof OduCltPort && dstPort instanceof OduCltPort) {
Device srcDevice = deviceService.getDevice(ingress.deviceId());
Device dstDevice = deviceService.getDevice(egress.deviceId());
// continue only if both OduClt port's Devices are of the same type
if (!(srcDevice.type().equals(dstDevice.type()))) {
print("Devices without same deviceType: SRC=%s and DST=%s", srcDevice.type(), dstDevice.type());
return;
}
CltSignalType signalType = ((OduCltPort) srcPort).signalType();
if (Device.Type.ROADM.equals(srcDevice.type())) {
intent = OpticalCircuitIntent.builder()
.appId(appId())
.key(key())
.src(ingress)
.dst(egress)
.signalType(CltSignalType.CLT_10GBE)
.signalType(signalType)
.bidirectional(bidirectional)
.build();
} else if (Device.Type.OTN.equals(srcDevice.type())) {
intent = OpticalOduIntent.builder()
.appId(appId())
.key(key())
.src(ingress)
.dst(egress)
.signalType(signalType)
.bidirectional(bidirectional)
.build();
} else {
print("Wrong Device Type for connect points %s and %s", ingress, egress);
return;
}
} else if (srcPort instanceof OchPort && dstPort instanceof OchPort) {
OduSignalType signalType = ((OchPort) srcPort).signalType();
intent = OpticalConnectivityIntent.builder()
.appId(appId())
.key(key())
.src(ingress)
.dst(egress)
.signalType(OduSignalType.ODU4)
.signalType(signalType)
.bidirectional(bidirectional)
.build();
} else {
print("Unable to create optical intent between connect points {} and {}", ingress, egress);
print("Unable to create optical intent between connect points %s and %s", ingress, egress);
return;
}
......
......@@ -29,6 +29,7 @@ import org.onosproject.net.intent.LinkCollectionIntent;
import org.onosproject.net.intent.MultiPointToSinglePointIntent;
import org.onosproject.net.intent.OpticalCircuitIntent;
import org.onosproject.net.intent.OpticalConnectivityIntent;
import org.onosproject.net.intent.OpticalOduIntent;
import org.onosproject.net.intent.PathIntent;
import org.onosproject.net.intent.PointToPointIntent;
import org.onosproject.net.intent.SinglePointToMultiPointIntent;
......@@ -118,6 +119,7 @@ public class IntentsListCommand extends AbstractShellCommand {
private IntentSummary summaryLinkCollection;
private IntentSummary summaryOpticalCircuit;
private IntentSummary summaryOpticalConnectivity;
private IntentSummary summaryOpticalOdu;
private IntentSummary summaryUnknownType;
/**
......@@ -136,6 +138,7 @@ public class IntentsListCommand extends AbstractShellCommand {
summaryLinkCollection = new IntentSummary("LinkCollection");
summaryOpticalCircuit = new IntentSummary("OpticalCircuit");
summaryOpticalConnectivity = new IntentSummary("OpticalConnectivity");
summaryOpticalOdu = new IntentSummary("OpticalOdu");
summaryUnknownType = new IntentSummary("UnknownType");
}
......@@ -196,6 +199,10 @@ public class IntentsListCommand extends AbstractShellCommand {
summaryOpticalConnectivity.update(intentState);
continue;
}
if (intent instanceof OpticalOduIntent) {
summaryOpticalOdu.update(intentState);
continue;
}
summaryUnknownType.update(intentState);
}
}
......@@ -219,6 +226,7 @@ public class IntentsListCommand extends AbstractShellCommand {
result.set("linkCollection", summaryLinkCollection.json(mapper));
result.set("opticalCircuit", summaryOpticalCircuit.json(mapper));
result.set("opticalConnectivity", summaryOpticalConnectivity.json(mapper));
result.set("opticalOdu", summaryOpticalOdu.json(mapper));
result.set("unknownType", summaryUnknownType.json(mapper));
result.set("all", summaryAll.json(mapper));
return result;
......@@ -237,6 +245,7 @@ public class IntentsListCommand extends AbstractShellCommand {
summaryLinkCollection.printState();
summaryOpticalCircuit.printState();
summaryOpticalConnectivity.printState();
summaryOpticalOdu.printState();
summaryUnknownType.printState();
summaryAll.printState();
}
......@@ -401,6 +410,9 @@ public class IntentsListCommand extends AbstractShellCommand {
} else if (intent instanceof OpticalConnectivityIntent) {
OpticalConnectivityIntent ci = (OpticalConnectivityIntent) intent;
print(" src=%s, dst=%s", ci.getSrc(), ci.getDst());
} else if (intent instanceof OpticalOduIntent) {
OpticalOduIntent ci = (OpticalOduIntent) intent;
print(" src=%s, dst=%s", ci.getSrc(), ci.getDst());
}
List<Intent> installable = service.getInstallableIntents(intent.key());
......
/*
* 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;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Collection of helper methods to convert various SignalTypes to OduSignalType, and to build OduSignalId.
*/
public final class OduSignalUtils {
private static final Logger log = LoggerFactory.getLogger(OduSignalUtils.class);
// prohibit instantiation
private OduSignalUtils() {}
/**
* Maps from OduClt SignalType to OduSignalType.
*
* @param cltSignalType OduClt port signal type
* @return OduSignalType the result of mapping CltSignalType to OduSignalType
*/
public static OduSignalType mappingCltSignalTypeToOduSignalType(CltSignalType cltSignalType) {
switch (cltSignalType) {
case CLT_1GBE:
return OduSignalType.ODU0;
case CLT_10GBE:
return OduSignalType.ODU2;
case CLT_40GBE:
return OduSignalType.ODU3;
case CLT_100GBE:
return OduSignalType.ODU4;
default:
log.error("Unsupported CltSignalType {}", cltSignalType);
return OduSignalType.ODU0;
}
}
/**
* Maps from OtuPort SignalType to OduSignalType.
*
* @param otuSignalType Otu port signal type
* @return OduSignalType the result of mapping OtuSignalType to OduSignalType
*/
public static OduSignalType mappingOtuSignalTypeToOduSignalType(OtuSignalType otuSignalType) {
switch (otuSignalType) {
case OTU2:
return OduSignalType.ODU2;
case OTU4:
return OduSignalType.ODU4;
default:
log.error("Unsupported OtuSignalType {}", otuSignalType);
return OduSignalType.ODU0;
}
}
/**
* Creates OduSignalId from OduSignalType and TributarySlots.
* @param oduSignalType - OduSignalType
* @param slots - a set of TributarySlots
* @return OduSignalId
*/
public static OduSignalId buildOduSignalId(OduSignalType oduSignalType, Set<TributarySlot> slots) {
int tributaryPortNumber = (int) slots.stream().findFirst().get().index();
int tributarySlotLen = oduSignalType.tributarySlots();
byte[] tributarySlotBitmap = new byte[OduSignalId.TRIBUTARY_SLOT_BITMAP_SIZE];
slots.forEach(ts -> tributarySlotBitmap[(byte) (ts.index() - 1) / 8] |= 0x1 << ((ts.index() - 1) % 8));
return OduSignalId.oduSignalId(tributaryPortNumber, tributarySlotLen, tributarySlotBitmap);
}
}
\ No newline at end of file
/*
* 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.intent;
import com.google.common.annotations.Beta;
import com.google.common.base.MoreObjects;
import org.onosproject.core.ApplicationId;
import org.onosproject.net.CltSignalType;
import org.onosproject.net.ConnectPoint;
import java.util.Collections;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* An optical layer intent between two OduClt ports - in an OTN Topology.
* No traffic selector or traffic treatment are needed.
*/
@Beta
public final class OpticalOduIntent extends Intent {
private final ConnectPoint src;
private final ConnectPoint dst;
private final CltSignalType signalType;
private final boolean isBidirectional;
/**
* Creates an optical ODU intent between the specified connection points.
*
* @param appId application identification
* @param key intent key
* @param src the source transponder port
* @param dst the destination transponder port
* @param signalType CltSignalType signal type
* @param isBidirectional indicate if intent is bidirectional
* @param priority priority to use for flows from this intent
*/
protected OpticalOduIntent(ApplicationId appId,
Key key,
ConnectPoint src,
ConnectPoint dst,
CltSignalType signalType,
boolean isBidirectional,
int priority) {
super(appId, key, Collections.emptyList(), priority);
this.src = checkNotNull(src);
this.dst = checkNotNull(dst);
this.signalType = checkNotNull(signalType);
this.isBidirectional = isBidirectional;
}
/**
* Returns a new optical ODU intent builder.
*
* @return intent builder
*/
public static Builder builder() {
return new Builder();
}
/**
* Builder for optical ODU intents.
*/
public static class Builder extends Intent.Builder {
private ConnectPoint src;
private ConnectPoint dst;
private CltSignalType signalType;
private boolean isBidirectional;
@Override
public Builder appId(ApplicationId appId) {
return (Builder) super.appId(appId);
}
@Override
public Builder key(Key key) {
return (Builder) super.key(key);
}
@Override
public Builder priority(int priority) {
return (Builder) super.priority(priority);
}
/**
* Sets the source for the intent that will be built.
*
* @param src source to use for built intent
* @return this builder
*/
public Builder src(ConnectPoint src) {
this.src = src;
return this;
}
/**
* Sets the destination for the intent that will be built.
*
* @param dst dest to use for built intent
* @return this builder
*/
public Builder dst(ConnectPoint dst) {
this.dst = dst;
return this;
}
/**
* Sets the ODU signal type for the intent that will be built.
*
* @param signalType signal type to use for built intent
* @return this builder
*/
public Builder signalType(CltSignalType signalType) {
this.signalType = signalType;
return this;
}
/**
* Sets the directionality of the intent.
*
* @param isBidirectional true if bidirectional, false if unidirectional
* @return this builder
*/
public Builder bidirectional(boolean isBidirectional) {
this.isBidirectional = isBidirectional;
return this;
}
/**
* Builds an optical ODU intent from the accumulated parameters.
*
* @return point to point intent
*/
public OpticalOduIntent build() {
return new OpticalOduIntent(
appId,
key,
src,
dst,
signalType,
isBidirectional,
priority
);
}
}
/**
* Constructor for serializer.
*/
protected OpticalOduIntent() {
super();
this.src = null;
this.dst = null;
this.signalType = null;
this.isBidirectional = false;
}
/**
* Returns the source transponder port.
*
* @return source transponder port
*/
public ConnectPoint getSrc() {
return src;
}
/**
* Returns the destination transponder port.
*
* @return source transponder port
*/
public ConnectPoint getDst() {
return dst;
}
/**
* Returns the CltSignalType signal type.
*
* @return CltSignalType signal type
*/
public CltSignalType getSignalType() {
return signalType;
}
/**
* Returns the directionality of the intent.
*
* @return true if bidirectional, false if unidirectional
*/
public boolean isBidirectional() {
return isBidirectional;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("id", id())
.add("key", key())
.add("appId", appId())
.add("priority", priority())
.add("resources", resources())
.add("src", src)
.add("dst", dst)
.add("signalType", signalType)
.add("isBidirectional", isBidirectional)
.toString();
}
}
\ No newline at end of file
......@@ -36,6 +36,7 @@ import org.onosproject.net.OchPort;
import org.onosproject.net.OduCltPort;
import org.onosproject.net.OduSignalId;
import org.onosproject.net.OduSignalType;
import org.onosproject.net.OduSignalUtils;
import org.onosproject.net.Port;
import org.onosproject.net.TributarySlot;
import org.onosproject.net.behaviour.TributarySlotQuery;
......@@ -276,7 +277,7 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu
}
private List<Resource> availableSlotResources(ConnectPoint src, ConnectPoint dst, CltSignalType signalType) {
OduSignalType oduSignalType = mappingCltSignalTypeToOduSignalType(signalType);
OduSignalType oduSignalType = OduSignalUtils.mappingCltSignalTypeToOduSignalType(signalType);
int requestedTsNum = oduSignalType.tributarySlots();
Set<TributarySlot> commonTributarySlots = findCommonTributarySlotsOnCps(src, dst);
if (commonTributarySlots.isEmpty()) {
......@@ -339,7 +340,7 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu
CltSignalType signalType,
boolean multiplexingSupported) {
OduSignalType oduSignalType = mappingCltSignalTypeToOduSignalType(signalType);
OduSignalType oduSignalType = OduSignalUtils.mappingCltSignalTypeToOduSignalType(signalType);
return Tools.stream(intentService.getIntents())
.filter(x -> x instanceof OpticalConnectivityIntent)
......@@ -509,23 +510,25 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu
OduSignalType ochPortOduSignalType;
if (srcPort instanceof OduCltPort) {
oduCltPortOduSignalType = mappingCltSignalTypeToOduSignalType(((OduCltPort) srcPort).signalType());
oduCltPortOduSignalType =
OduSignalUtils.mappingCltSignalTypeToOduSignalType(((OduCltPort) srcPort).signalType());
ochPortOduSignalType = ((OchPort) dstPort).signalType();
selectorBuilder.add(Criteria.matchOduSignalType(oduCltPortOduSignalType));
// use Instruction of OduSignalId only in case of ODU Multiplexing
if (oduCltPortOduSignalType != ochPortOduSignalType) {
OduSignalId oduSignalId = buildOduSignalId(ochPortOduSignalType, slots);
OduSignalId oduSignalId = OduSignalUtils.buildOduSignalId(ochPortOduSignalType, slots);
treatmentBuilder.add(Instructions.modL1OduSignalId(oduSignalId));
}
} else { // srcPort is OchPort
oduCltPortOduSignalType = mappingCltSignalTypeToOduSignalType(((OduCltPort) dstPort).signalType());
oduCltPortOduSignalType =
OduSignalUtils.mappingCltSignalTypeToOduSignalType(((OduCltPort) dstPort).signalType());
ochPortOduSignalType = ((OchPort) srcPort).signalType();
selectorBuilder.add(Criteria.matchOduSignalType(oduCltPortOduSignalType));
// use Criteria of OduSignalId only in case of ODU Multiplexing
if (oduCltPortOduSignalType != ochPortOduSignalType) {
OduSignalId oduSignalId = buildOduSignalId(ochPortOduSignalType, slots);
OduSignalId oduSignalId = OduSignalUtils.buildOduSignalId(ochPortOduSignalType, slots);
selectorBuilder.add(Criteria.matchOduSignalId(oduSignalId));
}
}
......@@ -544,19 +547,6 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu
return flowRule;
}
OduSignalId buildOduSignalId(OduSignalType ochPortSignalType, Set<TributarySlot> slots) {
int tributaryPortNumber = findFirstTributarySlotIndex(slots);
int tributarySlotLen = ochPortSignalType.tributarySlots();
byte[] tributarySlotBitmap = new byte[OduSignalId.TRIBUTARY_SLOT_BITMAP_SIZE];
slots.forEach(ts -> tributarySlotBitmap[(byte) (ts.index() - 1) / 8] |= 0x1 << ((ts.index() - 1) % 8));
return OduSignalId.oduSignalId(tributaryPortNumber, tributarySlotLen, tributarySlotBitmap);
}
private int findFirstTributarySlotIndex(Set<TributarySlot> tributarySlots) {
return (int) tributarySlots.stream().findFirst().get().index();
}
private boolean isMultiplexingSupported(ConnectPoint cp) {
Driver driver = driverService.getDriver(cp.deviceId());
return driver != null
......@@ -565,28 +555,6 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu
}
/**
* Maps from Intent's OduClt SignalType to OduSignalType.
*
* @param cltSignalType OduClt port signal type
* @return OduSignalType the result of mapping CltSignalType to OduSignalType
*/
OduSignalType mappingCltSignalTypeToOduSignalType(CltSignalType cltSignalType) {
switch (cltSignalType) {
case CLT_1GBE:
return OduSignalType.ODU0;
case CLT_10GBE:
return OduSignalType.ODU2;
case CLT_40GBE:
return OduSignalType.ODU3;
case CLT_100GBE:
return OduSignalType.ODU4;
default:
log.error("Unsupported CltSignalType {}", cltSignalType);
return OduSignalType.ODU0;
}
}
/**
* Finds the common TributarySlots available on the two connect points.
*
* @param src source connect point
......
......@@ -38,6 +38,7 @@ import org.onosproject.net.OchSignal;
import org.onosproject.net.OduCltPort;
import org.onosproject.net.OduSignalId;
import org.onosproject.net.OduSignalType;
import org.onosproject.net.OduSignalUtils;
import org.onosproject.net.Port;
import org.onosproject.net.PortNumber;
import org.onosproject.net.TributarySlot;
......@@ -429,7 +430,7 @@ public class OpticalCircuitIntentCompilerTest {
TrafficTreatment.Builder treatmentBuilder1 = DefaultTrafficTreatment.builder();
Set<TributarySlot> slots = new HashSet<>();
slots.add(TributarySlot.of(1));
OduSignalId oduSignalId = sut.buildOduSignalId(D1P2.signalType(), slots);
OduSignalId oduSignalId = OduSignalUtils.buildOduSignalId(D1P2.signalType(), slots);
treatmentBuilder1.add(Instructions.modL1OduSignalId(oduSignalId));
treatmentBuilder1.setOutput(ochSrcCP.port());
assertThat(rule1.treatment(), is(treatmentBuilder1.build()));
......
......@@ -163,6 +163,7 @@ import org.onosproject.net.intent.MplsPathIntent;
import org.onosproject.net.intent.MultiPointToSinglePointIntent;
import org.onosproject.net.intent.OpticalCircuitIntent;
import org.onosproject.net.intent.OpticalConnectivityIntent;
import org.onosproject.net.intent.OpticalOduIntent;
import org.onosproject.net.intent.OpticalPathIntent;
import org.onosproject.net.intent.PathIntent;
import org.onosproject.net.intent.PointToPointIntent;
......@@ -422,6 +423,7 @@ public final class KryoNamespaces {
OpticalConnectivityIntent.class,
OpticalPathIntent.class,
OpticalCircuitIntent.class,
OpticalOduIntent.class,
DiscreteResource.class,
ContinuousResource.class,
DiscreteResourceId.class,
......