Sho SHIMIZU
Committed by Gerrit Code Review

Define a Criterion for OchSginalType

Resolve ONOS-1846

Change-Id: I63462a3e2702c93b1d1c84a324bdbaa351bac633
......@@ -25,6 +25,7 @@ import org.onlab.packet.Ip6Address;
import org.onlab.packet.MacAddress;
import org.onlab.packet.MplsLabel;
import org.onlab.packet.VlanId;
import org.onosproject.net.tunnel.OchSignalType;
/**
* Factory class to create various traffic selection criteria.
......@@ -391,6 +392,16 @@ public final class Criteria {
return new OpticalSignalTypeCriterion(sigType, Type.OCH_SIGTYPE);
}
/**
* Create a match on OCh (Optical Channel) signal type.
*
* @param signalType OCh signal type
* @return match criterion
*/
public static Criterion matchOchSignalType(OchSignalType signalType) {
return new OchSignalTypeCriterion(signalType);
}
public static Criterion dummy() {
return new DummyCriterion();
}
......
/*
* 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.tunnel.OchSignalType;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Implementation of OCh (Optical Channel) singal type criterion.
*/
public class OchSignalTypeCriterion implements Criterion {
private final OchSignalType signalType;
/**
* Creates a criterion with the specified value.
*
* @param signalType OCh signal type
*/
OchSignalTypeCriterion(OchSignalType signalType) {
this.signalType = checkNotNull(signalType);
}
@Override
public Type type() {
return Type.OCH_SIGTYPE;
}
/**
* Returns the OCh signal type to match.
*
* @return the OCh signal type to match
*/
public OchSignalType signalType() {
return signalType;
}
@Override
public int hashCode() {
return Objects.hash(signalType);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof OchSignalTypeCriterion)) {
return false;
}
final OchSignalTypeCriterion that = (OchSignalTypeCriterion) obj;
return Objects.equals(this.signalType, that.signalType);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("signalType", signalType)
.toString();
}
}
......@@ -27,6 +27,7 @@ import org.onlab.packet.MplsLabel;
import org.onlab.packet.VlanId;
import com.google.common.testing.EqualsTester;
import org.onosproject.net.tunnel.OchSignalType;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
......@@ -220,6 +221,10 @@ public class CriteriaTest {
Criterion sameAsMatchLambda1 = Criteria.matchLambda(lambda1);
Criterion matchLambda2 = Criteria.matchLambda(lambda2);
Criterion matchOchSignalType1 = Criteria.matchOchSignalType(OchSignalType.FIX_GRID);
Criterion sameAsMatchOchSignalType1 = Criteria.matchOchSignalType(OchSignalType.FIX_GRID);
Criterion matchOchSignalType2 = Criteria.matchOchSignalType(OchSignalType.FLEX_GRID);
Criterion matchIndexedLambda1 = Criteria.matchLambda(Lambda.indexedLambda(1));
Criterion sameAsMatchIndexedLambda1 = Criteria.matchLambda(Lambda.indexedLambda(1));
Criterion matchIndexedLambda2 = Criteria.matchLambda(Lambda.indexedLambda(2));
......@@ -1057,6 +1062,17 @@ public class CriteriaTest {
.testEquals();
}
/**
* Test the equals() method of the OchSignalTypeCriterion class.
*/
@Test
public void testOchSignalTypeCriterionEquals() {
new EqualsTester()
.addEqualityGroup(matchOchSignalType1, sameAsMatchOchSignalType1)
.addEqualityGroup(matchOchSignalType2)
.testEquals();
}
// OpticalSignalTypeCriterion class
/**
......
......@@ -102,6 +102,7 @@ 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.OchSignalTypeCriterion;
import org.onosproject.net.flow.criteria.OpticalSignalTypeCriterion;
import org.onosproject.net.flow.criteria.PortCriterion;
import org.onosproject.net.flow.criteria.SctpPortCriterion;
......@@ -294,6 +295,7 @@ public final class KryoNamespaces {
LambdaCriterion.class,
IndexedLambdaCriterion.class,
OchSignalCriterion.class,
OchSignalTypeCriterion.class,
OpticalSignalTypeCriterion.class,
Criterion.class,
Criterion.Type.class,
......