Sho SHIMIZU
Committed by Gerrit Code Review

Define Lambda interface representing wavelength and implementations

Two Lambda implementations are defined.
- IndexedLambda
- OchSignal

Change-Id: I36763390f61abd9f861e76edab63f558ae97e8a2
/*
* Copyright 2015 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 com.google.common.base.MoreObjects;
/**
* Implementation of Lambda simply designated by an index number of wavelength.
*/
public class IndexedLambda implements Lambda {
private final long lambda;
/**
* Creates an instance representing the wavelength specified by the given index number.
*
* @param lambda index number of wavelength
*/
IndexedLambda(long lambda) {
this.lambda = lambda;
}
@Override
public int hashCode() {
return (int) (lambda ^ (lambda >>> 32));
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof IndexedLambda)) {
return false;
}
final IndexedLambda that = (IndexedLambda) obj;
return this.lambda == that.lambda;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("lambda", lambda)
.toString();
}
}
/*
* Copyright 2015 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;
/**
* Abstraction of wavelength. Currently, this is just a marker interface
*/
public interface Lambda {
/**
* Create an Lambda instance with the specified wavelength index number.
*
* @param lambda index number
* @return an instance
*/
static Lambda indexedLambda(long lambda) {
return new IndexedLambda(lambda);
}
/**
* Creates a Lambda instance with the specified arguments.
*
* @param gridType grid type
* @param channelSpacing channel spacing
* @param spacingMultiplier channel spacing multiplier
* @param slotGranularity slot width granularity
*/
static Lambda ochSignal(GridType gridType, ChannelSpacing channelSpacing,
int spacingMultiplier, int slotGranularity) {
return new OchSignal(gridType, channelSpacing, spacingMultiplier, slotGranularity);
}
}
/*
* Copyright 2015 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 com.google.common.base.MoreObjects;
import org.onlab.util.Frequency;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Implementation of Lambda representing OCh (Optical Channel) Signal.
*
* <p>
* See ITU G.709 "Interfaces for the Optical Transport Network (OTN)".
* </p>
*/
// TODO: consider which is better, OchSignal or OpticalChannelSignal
public class OchSignal implements Lambda {
private static final Frequency CENTER_FREQUENCY = Frequency.ofTHz(193.1);
private static final Frequency FLEX_GRID_SLOT = Frequency.ofGHz(12.5);
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;
/**
* Creates an instance with the specified arguments.
*
* @param gridType grid type
* @param channelSpacing channel spacing
* @param spacingMultiplier channel spacing multiplier
* @param slotGranularity slot width granularity
*/
OchSignal(GridType gridType, ChannelSpacing channelSpacing,
int spacingMultiplier, int slotGranularity) {
this.gridType = checkNotNull(gridType);
this.channelSpacing = checkNotNull(channelSpacing);
// TODO: check the precondition for spacingMultiplier. Is negative value permitted?
this.spacingMultiplier = spacingMultiplier;
checkArgument(slotGranularity > 0, "slotGranularity must be more than 0, but %s", slotGranularity);
this.slotGranularity = slotGranularity;
}
/**
* 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.
*
* @return slot width
*/
public Frequency slotWidth() {
return FLEX_GRID_SLOT.multiply(slotGranularity);
}
@Override
public int hashCode() {
return Objects.hash(gridType, channelSpacing, spacingMultiplier, slotGranularity);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof OchSignal)) {
return false;
}
final OchSignal other = (OchSignal) obj;
return Objects.equals(this.gridType, other.gridType)
&& Objects.equals(this.channelSpacing, other.channelSpacing)
&& Objects.equals(this.spacingMultiplier, other.spacingMultiplier)
&& Objects.equals(this.slotGranularity, other.slotGranularity);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("gridType", gridType)
.add("channelSpacing", channelSpacing)
.add("spacingMultiplier", spacingMultiplier)
.add("slotGranularity", slotGranularity)
.toString();
}
}
/*
* Copyright 2015 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 com.google.common.testing.EqualsTester;
import org.junit.Test;
public class IndexedLambdaTest {
@Test
public void testEquality() {
new EqualsTester()
.addEqualityGroup(Lambda.indexedLambda(10), Lambda.indexedLambda(10))
.addEqualityGroup(Lambda.indexedLambda(11), Lambda.indexedLambda(11), Lambda.indexedLambda(11))
.testEquals();
}
}
......@@ -18,7 +18,6 @@ package org.onosproject.store.serializers;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import org.onlab.packet.ChassisId;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.Ip4Prefix;
......@@ -57,14 +56,16 @@ import org.onosproject.net.Element;
import org.onosproject.net.GridType;
import org.onosproject.net.HostId;
import org.onosproject.net.HostLocation;
import org.onosproject.net.IndexedLambda;
import org.onosproject.net.Link;
import org.onosproject.net.LinkKey;
import org.onosproject.net.OchPort;
import org.onosproject.net.OchSignal;
import org.onosproject.net.OduCltPort;
import org.onosproject.net.OduSignalType;
import org.onosproject.net.OmsPort;
import org.onosproject.net.Port;
import org.onosproject.net.PortNumber;
import org.onosproject.net.OduSignalType;
import org.onosproject.net.device.DefaultDeviceDescription;
import org.onosproject.net.device.DefaultPortDescription;
import org.onosproject.net.flow.CompletedBatchOperation;
......@@ -384,6 +385,8 @@ public final class KryoNamespaces {
.register(ChannelSpacing.class)
.register(OduCltPort.class)
.register(OduCltPort.SignalType.class)
.register(IndexedLambda.class)
.register(OchSignal.class)
.register(
MplsIntent.class,
MplsPathIntent.class,
......
......@@ -324,6 +324,18 @@ public class KryoSerializerTest {
}
@Test
public void testIndexedLambda() {
testSerializedEquals(org.onosproject.net.Lambda.indexedLambda(10L));
}
@Test
public void testOchSignal() {
testSerializedEquals(org.onosproject.net.Lambda.ochSignal(
GridType.DWDM, ChannelSpacing.CHL_100GHZ, 1, 1
));
}
@Test
public void testDefaultLinkResourceRequest() {
testSerializable(DefaultLinkResourceRequest.builder(IntentId.valueOf(2501), ImmutableList.of())
.addLambdaRequest()
......