Sho SHIMIZU
Committed by Gerrit Code Review

Populate OchSignal with OchPort

Change-Id: I2e9031972e286f25f9caa32fac26d37e3efd10b5
......@@ -20,6 +20,7 @@ import org.onlab.util.Frequency;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Implementation of OCh port (Optical Channel).
......@@ -33,38 +34,25 @@ public class OchPort extends DefaultPort {
private final OduSignalType signalType;
private final boolean isTunable;
private final GridType gridType;
private final ChannelSpacing channelSpacing;
// Frequency = 193.1 THz + spacingMultiplier * channelSpacing
private final int spacingMultiplier;
// Slot width = slotGranularity * 12.5 GHz
private final int slotGranularity;
private final OchSignal lambda;
/**
* Creates an OCh port in the specified network element.
*
* @param element parent network element
* @param number port number
* @param isEnabled port enabled state
* @param signalType ODU signal type
* @param isTunable maximum frequency in MHz
* @param gridType grid type
* @param channelSpacing channel spacing
* @param spacingMultiplier channel spacing multiplier
* @param slotGranularity slot width granularity
* @param annotations optional key/value annotations
* @param element parent network element
* @param number port number
* @param isEnabled port enabled state
* @param signalType ODU signal type
* @param isTunable maximum frequency in MHz
* @param lambda OCh signal
* @param annotations optional key/value annotations
*/
public OchPort(Element element, PortNumber number, boolean isEnabled, OduSignalType signalType,
boolean isTunable, GridType gridType, ChannelSpacing channelSpacing,
int spacingMultiplier, int slotGranularity, Annotations... annotations) {
boolean isTunable, OchSignal lambda, Annotations... annotations) {
super(element, number, isEnabled, Type.OCH, 0, annotations);
this.signalType = signalType;
this.isTunable = isTunable;
this.gridType = gridType;
this.channelSpacing = channelSpacing;
this.spacingMultiplier = spacingMultiplier;
this.slotGranularity = slotGranularity;
this.lambda = checkNotNull(lambda);
}
/**
......@@ -86,63 +74,17 @@ public class OchPort extends DefaultPort {
}
/**
* Returns grid type.
*
* @return grid type
*/
public GridType gridType() {
return gridType;
}
/**
* Returns channel spacing.
*
* @return channel spacing
*/
public ChannelSpacing channelSpacing() {
return channelSpacing;
}
/**
* Returns spacing multiplier.
*
* @return spacing multiplier
*/
public int spacingMultiplier() {
return spacingMultiplier;
}
/**
* Returns slow width granularity.
*
* @return slow width granularity
*/
public int slotGranularity() {
return slotGranularity;
}
/**
* Returns central frequency in MHz.
*
* @return frequency in MHz
*/
public Frequency centralFrequency() {
return CENTER_FREQUENCY.add(channelSpacing().frequency().multiply(spacingMultiplier));
}
/**
* Returns slot width.
* Returns OCh signal.
*
* @return slot width
* @return OCh signal
*/
public Frequency slotWidth() {
return FLEX_GRID_SLOT.multiply(slotGranularity);
public OchSignal lambda() {
return lambda;
}
@Override
public int hashCode() {
return Objects.hash(number(), isEnabled(), type(), signalType, isTunable,
gridType, channelSpacing, spacingMultiplier, slotGranularity, annotations());
return Objects.hash(number(), isEnabled(), type(), signalType, isTunable, lambda, annotations());
}
@Override
......@@ -157,10 +99,7 @@ public class OchPort extends DefaultPort {
Objects.equals(this.isEnabled(), other.isEnabled()) &&
Objects.equals(this.signalType, other.signalType) &&
Objects.equals(this.isTunable, other.isTunable) &&
Objects.equals(this.gridType, other.gridType) &&
Objects.equals(this.channelSpacing, other.channelSpacing) &&
Objects.equals(this.spacingMultiplier, other.spacingMultiplier) &&
Objects.equals(this.slotGranularity, other.slotGranularity) &&
Objects.equals(this.lambda, other.lambda) &&
Objects.equals(this.annotations(), other.annotations());
}
return false;
......@@ -175,10 +114,7 @@ public class OchPort extends DefaultPort {
.add("type", type())
.add("signalType", signalType)
.add("isTunable", isTunable)
.add("gridType", gridType)
.add("channelSpacing", channelSpacing)
.add("spacingMultiplier", spacingMultiplier)
.add("slotGranularity", slotGranularity)
.add("lambda", lambda)
.toString();
}
}
......
......@@ -16,13 +16,14 @@
package org.onosproject.net.device;
import com.google.common.base.MoreObjects;
import org.onosproject.net.ChannelSpacing;
import org.onosproject.net.GridType;
import org.onosproject.net.OchSignal;
import org.onosproject.net.OduSignalType;
import org.onosproject.net.Port;
import org.onosproject.net.PortNumber;
import org.onosproject.net.OduSignalType;
import org.onosproject.net.SparseAnnotations;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Default implementation of immutable OCh port description.
*/
......@@ -30,61 +31,41 @@ public class OchPortDescription extends DefaultPortDescription {
private final OduSignalType signalType;
private final boolean isTunable;
private final GridType gridType;
private final ChannelSpacing channelSpacing;
// Frequency = 193.1 THz + spacingMultiplier * channelSpacing
private final int spacingMultiplier;
// Slot width = slotGranularity * 12.5 GHz
private final int slotGranularity;
private final OchSignal lambda;
/**
* Creates OCH port description based on the supplied information.
*
* @param number port number
* @param isEnabled port enabled state
* @param signalType ODU signal type
* @param isTunable tunable wavelength capability
* @param gridType grid type
* @param channelSpacing channel spacing
* @param spacingMultiplier channel spacing multiplier
* @param slotGranularity slow width granularity
* @param annotations optional key/value annotations map
* @param number port number
* @param isEnabled port enabled state
* @param signalType ODU signal type
* @param isTunable tunable wavelength capability
* @param lambda Och signal
* @param annotations optional key/value annotations map
*/
public OchPortDescription(PortNumber number, boolean isEnabled, OduSignalType signalType,
boolean isTunable, GridType gridType,
ChannelSpacing channelSpacing,
int spacingMultiplier, int slotGranularity, SparseAnnotations... annotations) {
boolean isTunable, OchSignal lambda, SparseAnnotations... annotations) {
super(number, isEnabled, Port.Type.OCH, 0, annotations);
this.signalType = signalType;
this.isTunable = isTunable;
this.gridType = gridType;
this.channelSpacing = channelSpacing;
this.spacingMultiplier = spacingMultiplier;
this.slotGranularity = slotGranularity;
this.lambda = checkNotNull(lambda);
}
/**
* Creates OCH port description based on the supplied information.
*
* @param base PortDescription to get basic information from
* @param signalType ODU signal type
* @param isTunable tunable wavelength capability
* @param gridType grid type
* @param channelSpacing channel spacing
* @param spacingMultiplier channel spacing multiplier
* @param slotGranularity slot width granularity
* @param annotations optional key/value annotations map
* @param base PortDescription to get basic information from
* @param signalType ODU signal type
* @param isTunable tunable wavelength capability
* @param lambda OCh signal
* @param annotations optional key/value annotations map
*/
public OchPortDescription(PortDescription base, OduSignalType signalType, boolean isTunable,
GridType gridType, ChannelSpacing channelSpacing,
int spacingMultiplier, int slotGranularity, SparseAnnotations annotations) {
OchSignal lambda, SparseAnnotations annotations) {
super(base, annotations);
this.signalType = signalType;
this.isTunable = isTunable;
this.gridType = gridType;
this.channelSpacing = channelSpacing;
this.spacingMultiplier = spacingMultiplier;
this.slotGranularity = slotGranularity;
this.lambda = checkNotNull(lambda);
}
/**
......@@ -106,39 +87,12 @@ public class OchPortDescription extends DefaultPortDescription {
}
/**
* Returns grid type.
*
* @return grid type
*/
public GridType gridType() {
return gridType;
}
/**
* Returns channel spacing.
*
* @return channel spacing
*/
public ChannelSpacing channelSpacing() {
return channelSpacing;
}
/**
* Returns channel spacing multiplier.
*
* @return channel spacing multiplier
*/
public int spacingMultiplier() {
return spacingMultiplier;
}
/**
* Returns slot width granularity.
* Returns OCh signal.
*
* @return slot width granularity
* @return OCh signal
*/
public int slotGranularity() {
return slotGranularity;
public OchSignal lambda() {
return lambda;
}
@Override
......@@ -149,10 +103,7 @@ public class OchPortDescription extends DefaultPortDescription {
.add("type", type())
.add("signalType", signalType)
.add("isTunable", isTunable)
.add("gridType", gridType)
.add("channelSpacing", channelSpacing)
.add("spacingMultiplier", spacingMultiplier)
.add("slotGranularity", slotGranularity)
.add("lambda", lambda)
.add("annotations", annotations())
.toString();
}
......
......@@ -1035,8 +1035,7 @@ public class GossipDeviceStore
case OCH:
OchPortDescription ochPortDesc = (OchPortDescription) portDesc.value();
return new OchPort(device, number, isEnabled, ochPortDesc.signalType(),
ochPortDesc.isTunable(), ochPortDesc.gridType(), ochPortDesc.channelSpacing(),
ochPortDesc.spacingMultiplier(), ochPortDesc.slotGranularity(), annotations);
ochPortDesc.isTunable(), ochPortDesc.lambda(), annotations);
case ODUCLT:
OduCltPortDescription oduCltPortDesc = (OduCltPortDescription) portDesc.value();
return new OduCltPort(device, number, isEnabled, oduCltPortDesc.signalType(), annotations);
......
......@@ -44,6 +44,7 @@ import org.onosproject.net.Link;
import org.onosproject.net.Link.Type;
import org.onosproject.net.LinkKey;
import org.onosproject.net.OchPort;
import org.onosproject.net.OchSignal;
import org.onosproject.net.OduCltPort;
import org.onosproject.net.OmsPort;
import org.onosproject.net.PortNumber;
......@@ -121,6 +122,8 @@ public class KryoSerializerTest {
.remove("A1")
.set("B3", "b3")
.build();
private static final OchSignal OCH_SIGNAL1 = (OchSignal) org.onosproject.net.Lambda.ochSignal(
GridType.DWDM, ChannelSpacing.CHL_100GHZ, -8, 4);
private KryoSerializer serializer;
......@@ -193,10 +196,8 @@ public class KryoSerializerTest {
@Test
public void testOchPort() {
testSerializedEquals(new OchPort(DEV1, P1, true, OduSignalType.ODU0, false, GridType.DWDM,
ChannelSpacing.CHL_100GHZ, -8, 4));
testSerializedEquals(new OchPort(DEV1, P1, true, OduSignalType.ODU0, false, GridType.DWDM,
ChannelSpacing.CHL_100GHZ, -8, 4, A1_2));
testSerializedEquals(new OchPort(DEV1, P1, true, OduSignalType.ODU0, false, OCH_SIGNAL1));
testSerializedEquals(new OchPort(DEV1, P1, true, OduSignalType.ODU0, false, OCH_SIGNAL1, A1_2));
}
@Test
......