Jimmy Yan
Committed by Gerrit Code Review

Use LambdaQuery in OpenFlowDeviceProvider to get details for optical ports and f…

…ix OmsPort totalChannels()

Change-Id: I09bee1ad1cbf4b8d7185c2b022ffed4d8b2ef2e7
......@@ -37,7 +37,7 @@ public interface OmsPort extends Port {
*/
default short totalChannels() {
Frequency diff = maxFrequency().subtract(minFrequency());
return (short) (diff.asHz() / grid().asHz());
return (short) (diff.asHz() / grid().asHz() + 1);
}
/**
......
......@@ -91,7 +91,7 @@ public class OmsPortHelperTest {
assertThat(oms.maxFrequency(), is(maxF));
assertThat(oms.minFrequency(), is(minF));
assertThat(oms.grid(), is(grid));
assertThat("(33-3)/2 = 15", oms.totalChannels(), is((short) 15));
assertThat("((33-3)/2)+1 = 16", oms.totalChannels(), is((short) 16));
}
}
......
......@@ -115,7 +115,7 @@ public class DefaultOmsPortTest {
assertThat(oms.maxFrequency(), is(maxFrequency));
assertThat(oms.minFrequency(), is(minFrequency));
assertThat(oms.grid(), is(grid));
assertThat("(33-3)/2 = 15", oms.totalChannels(), is((short) 15));
assertThat("((33-3)/2)+1 = 16", oms.totalChannels(), is((short) 16));
}
}
......
/*
* 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.driver.optical.query;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import org.onosproject.net.ChannelSpacing;
import org.onosproject.net.OchSignal;
import org.onosproject.net.PortNumber;
import org.onosproject.net.behaviour.LambdaQuery;
import org.onosproject.net.driver.AbstractHandlerBehaviour;
/**
* Lambda query implementation for Oplink ROADM.
*
* An Oplink ROADM port exposes OMSn resources: 88 lambdas with 50GHz width (fixed grid).
*
* Channel id: Nominal central frequency = 193.1 THz + spacingMultiplier * channelSpacing).
* Channel (-28 to 59): starting from 191.7 THz to 196.05 THz, Increment by 50GHz.
*/
public class OplinkRoadmLambdaQuery extends AbstractHandlerBehaviour implements LambdaQuery {
private static final int LAMBDA_COUNT = 88;
private static final int CENTER_OFFSET = 29;
@Override
public Set<OchSignal> queryLambdas(PortNumber port) {
return IntStream.rangeClosed(1, LAMBDA_COUNT)
.mapToObj(x -> OchSignal.newDwdmSlot(ChannelSpacing.CHL_50GHZ, x - CENTER_OFFSET))
.collect(Collectors.toSet());
}
}
\ No newline at end of file
......@@ -17,7 +17,7 @@
<drivers>
<driver name="linc-oe" extends="default"
manufacturer="FlowForwarding.org" hwVersion="Unknown"
swVersion="LINC-OE OpenFlow Software Switch 1.1">
swVersion="LINC(-OE)? OpenFlow Software Switch 1.1">
<behaviour api="org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver"
impl="org.onosproject.driver.optical.handshaker.OfOpticalSwitchImplLinc13"/>
<behaviour api="org.onosproject.net.behaviour.LambdaQuery"
......@@ -52,6 +52,8 @@
swVersion="of-agent">
<behaviour api="org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver"
impl="org.onosproject.driver.optical.handshaker.OplinkRoadmHandshaker"/>
<behaviour api="org.onosproject.net.behaviour.LambdaQuery"
impl="org.onosproject.driver.optical.query.OplinkRoadmLambdaQuery"/>
<behaviour api="org.onosproject.net.optical.OpticalDevice"
impl="org.onosproject.net.optical.DefaultOpticalDevice"/>
</driver>
......
......@@ -32,10 +32,12 @@ import static org.slf4j.LoggerFactory.getLogger;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
......@@ -62,6 +64,7 @@ import org.onosproject.net.OtuSignalType;
import org.onosproject.net.Port;
import org.onosproject.net.PortNumber;
import org.onosproject.net.SparseAnnotations;
import org.onosproject.net.behaviour.LambdaQuery;
import org.onosproject.net.device.DefaultDeviceDescription;
import org.onosproject.net.device.DefaultPortDescription;
import org.onosproject.net.device.DefaultPortStatistics;
......@@ -71,6 +74,8 @@ import org.onosproject.net.device.DeviceProviderRegistry;
import org.onosproject.net.device.DeviceProviderService;
import org.onosproject.net.device.PortDescription;
import org.onosproject.net.device.PortStatistics;
import org.onosproject.net.driver.DriverHandler;
import org.onosproject.net.driver.HandlerBehaviour;
import org.onosproject.net.provider.AbstractProvider;
import org.onosproject.net.provider.ProviderId;
import org.onosproject.openflow.controller.Dpid;
......@@ -479,7 +484,7 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
LOG.debug("Ports Of{}", portsOf);
portsOf.forEach(
op -> {
portDescs.add(buildPortDescription(type, op));
portDescs.add(buildPortDescription(type, op, opsw));
}
);
});
......@@ -540,9 +545,10 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
return annotations;
}
private PortDescription buildPortDescription(PortDescPropertyType ptype, OFObject port) {
private PortDescription buildPortDescription(PortDescPropertyType ptype, OFObject port,
OpenFlowOpticalSwitch opsw) {
if (port instanceof OFPortOptical) {
return buildPortDescription(ptype, (OFPortOptical) port);
return buildPortDescription(ptype, (OFPortOptical) port, opsw);
}
return buildPortDescription(ptype, (OFExpPort) port);
}
......@@ -681,7 +687,8 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
* @param port the port to build from.
* @return portDescription for the port.
*/
private PortDescription buildPortDescription(PortDescPropertyType ptype, OFPortOptical port) {
private PortDescription buildPortDescription(PortDescPropertyType ptype, OFPortOptical port,
OpenFlowOpticalSwitch opsw) {
checkArgument(port.getDesc().size() >= 1);
// Minimally functional fixture. This needs to be fixed as we add better support.
......@@ -706,8 +713,35 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
case 2: // OMS port
// Assume complete optical spectrum and 50 GHz grid
// LINC-OE is only supported optical OF device for now
return omsPortDescription(portNo, enabled,
Spectrum.U_BAND_MIN, Spectrum.O_BAND_MAX, Frequency.ofGHz(50), annotations);
Set<OchSignal> signals = null;
if (opsw instanceof HandlerBehaviour) {
DriverHandler driverHandler = ((HandlerBehaviour) opsw).handler();
if (driverHandler != null && driverHandler.hasBehaviour(LambdaQuery.class)) {
try {
signals = driverHandler.behaviour(LambdaQuery.class).queryLambdas(portNo);
} catch (NullPointerException e) {
signals = null;
}
}
}
Frequency minFreq;
Frequency maxFreq;
Frequency channelSpacing;
if (signals == null || signals.isEmpty()) {
minFreq = Spectrum.U_BAND_MIN;
maxFreq = Spectrum.O_BAND_MAX;
channelSpacing = Frequency.ofGHz(50);
} else {
Comparator<OchSignal> compare =
(OchSignal a, OchSignal b) -> a.spacingMultiplier() - b.spacingMultiplier();
OchSignal minOch = Collections.min(signals, compare);
OchSignal maxOch = Collections.max(signals, compare);
minFreq = minOch.centralFrequency();
maxFreq = maxOch.centralFrequency();
channelSpacing = minOch.channelSpacing().frequency();
}
return omsPortDescription(portNo, enabled, minFreq,
maxFreq, channelSpacing, annotations);
case 5: // OCH port
OchSignal signal = new OchSignal(GridType.DWDM, ChannelSpacing.CHL_50GHZ, 0, 4);
return ochPortDescription(portNo, enabled, OduSignalType.ODU4,
......