Sho SHIMIZU
Committed by Gerrit Code Review

Define a Criterion for OchSignal

Resolve ONOS-1844

Change-Id: I775a64ad6d6d3f1a046a6f7895a412c71c17ff16
......@@ -15,6 +15,8 @@
*/
package org.onosproject.net.flow.criteria;
import org.onosproject.net.Lambda;
import org.onosproject.net.OchSignal;
import org.onosproject.net.PortNumber;
import org.onosproject.net.flow.criteria.Criterion.Type;
import org.onlab.packet.IpPrefix;
......@@ -362,6 +364,20 @@ public final class Criteria {
}
/**
* Creates a match on lambda using the specified value.
*
* @param lambda lambda
* @return match criterion
*/
public static Criterion matchLambda(Lambda lambda) {
if (lambda instanceof OchSignal) {
return new OchSignalCriterion((OchSignal) lambda);
} else {
throw new UnsupportedOperationException(String.format("Unsupported type of Lambda: %s", lambda));
}
}
/**
* Creates a match on optical signal type using the specified value.
*
* @param sigType optical signal type (8 bits unsigned integer)
......
/*
* 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.flow.criteria;
import com.google.common.base.MoreObjects;
import org.onosproject.net.OchSignal;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Implementation of OCh (Optical Channel) signal criterion.
* This criterion is based on the specification of "OFPXMT_EXP_OCH_SIGID" in
* Open Networking Foundation "Optical Transport Protocol Extension Version 1.0", but
* defined in protocol agnostic way.
*/
public final class OchSignalCriterion implements Criterion {
private final OchSignal lambda;
/**
* Create an instance with the specified OCh signal.
*
* @param lambda OCh signal
*/
OchSignalCriterion(OchSignal lambda) {
this.lambda = checkNotNull(lambda);
}
@Override
public Type type() {
return Type.OCH_SIGID;
}
/**
* Returns the OCh signal to match.
*
* @return the OCh signal to match
*/
public OchSignal lambda() {
return lambda;
}
@Override
public int hashCode() {
return Objects.hash(lambda);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof OchSignalCriterion)) {
return false;
}
final OchSignalCriterion that = (OchSignalCriterion) obj;
return Objects.equals(this.lambda, that.lambda);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("lambda", lambda)
.toString();
}
}
......@@ -16,6 +16,9 @@
package org.onosproject.net.flow.criteria;
import org.junit.Test;
import org.onosproject.net.ChannelSpacing;
import org.onosproject.net.GridType;
import org.onosproject.net.Lambda;
import org.onosproject.net.PortNumber;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.Ip6Address;
......@@ -223,6 +226,13 @@ public class CriteriaTest {
Criterion sameAsMatchSignalLambda1 = Criteria.matchOpticalSignalType(signalLambda1);
Criterion matchSignalLambda2 = Criteria.matchOpticalSignalType(signalLambda2);
Criterion matchOchSignal1 =
Criteria.matchLambda(Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_100GHZ, 4, 8));
Criterion sameAsMatchOchSignal1 =
Criteria.matchLambda(Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_100GHZ, 4, 8));
Criterion matchOchSignal2 =
Criteria.matchLambda(Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_50GHZ, 4, 8));
/**
* Checks that a Criterion object has the proper type, and then converts
* it to the proper type.
......@@ -1027,6 +1037,14 @@ public class CriteriaTest {
.testEquals();
}
@Test
public void testOchSignalCriterionEquals() {
new EqualsTester()
.addEqualityGroup(matchOchSignal1, sameAsMatchOchSignal1)
.addEqualityGroup(matchOchSignal2)
.testEquals();
}
// OpticalSignalTypeCriterion class
/**
......
......@@ -100,6 +100,7 @@ import org.onosproject.net.flow.criteria.Icmpv6TypeCriterion;
import org.onosproject.net.flow.criteria.LambdaCriterion;
import org.onosproject.net.flow.criteria.MetadataCriterion;
import org.onosproject.net.flow.criteria.MplsCriterion;
import org.onosproject.net.flow.criteria.OchSignalCriterion;
import org.onosproject.net.flow.criteria.OpticalSignalTypeCriterion;
import org.onosproject.net.flow.criteria.PortCriterion;
import org.onosproject.net.flow.criteria.SctpPortCriterion;
......@@ -290,6 +291,7 @@ public final class KryoNamespaces {
MplsCriterion.class,
IPv6ExthdrFlagsCriterion.class,
LambdaCriterion.class,
OchSignalCriterion.class,
OpticalSignalTypeCriterion.class,
Criterion.class,
Criterion.Type.class,
......