Sho SHIMIZU

ONOS-2037: Fix cast exception on execution of "flows -j" command

Change-Id: If481573f405d812b0b103e1752a559d8f81d6bd8
......@@ -37,7 +37,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.OpticalSignalTypeCriterion;
import org.onosproject.net.flow.criteria.OchSignalTypeCriterion;
import org.onosproject.net.flow.criteria.PortCriterion;
import org.onosproject.net.flow.criteria.SctpPortCriterion;
import org.onosproject.net.flow.criteria.TcpPortCriterion;
......@@ -334,9 +334,9 @@ public final class CriterionCodec extends JsonCodec<Criterion> {
private static class FormatOchSigType implements CriterionTypeFormatter {
@Override
public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) {
final OpticalSignalTypeCriterion opticalSignalTypeCriterion =
(OpticalSignalTypeCriterion) criterion;
return root.put("signalType", opticalSignalTypeCriterion.signalType());
final OchSignalTypeCriterion ochSignalTypeCriterion =
(OchSignalTypeCriterion) criterion;
return root.put("ochSignalType", ochSignalTypeCriterion.signalType().name());
}
}
......
......@@ -26,6 +26,7 @@ import org.onlab.packet.MplsLabel;
import org.onlab.packet.VlanId;
import org.onosproject.codec.CodecContext;
import org.onosproject.codec.JsonCodec;
import org.onosproject.net.OchSignalType;
import org.onosproject.net.PortNumber;
import org.onosproject.net.flow.criteria.Criteria;
import org.onosproject.net.flow.criteria.Criterion;
......@@ -416,7 +417,7 @@ public class CriterionCodecTest {
*/
@Test
public void matchOpticalSignalTypeTest() {
Criterion criterion = Criteria.matchOpticalSignalType((byte) 250);
Criterion criterion = Criteria.matchOchSignalType(OchSignalType.FIXED_GRID);
ObjectNode result = criterionCodec.encode(criterion, context);
assertThat(result, matchesCriterion(criterion));
}
......
......@@ -37,7 +37,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.OpticalSignalTypeCriterion;
import org.onosproject.net.flow.criteria.OchSignalTypeCriterion;
import org.onosproject.net.flow.criteria.PortCriterion;
import org.onosproject.net.flow.criteria.SctpPortCriterion;
import org.onosproject.net.flow.criteria.TcpPortCriterion;
......@@ -469,11 +469,11 @@ public final class CriterionJsonMatcher extends
* @param criterion criterion to match
* @return true if the JSON matches the criterion, false otherwise.
*/
private boolean matchCriterion(OpticalSignalTypeCriterion criterion) {
final short signalType = criterion.signalType();
final short jsonSignalType = jsonCriterion.get("signalType").shortValue();
if (signalType != jsonSignalType) {
description.appendText("signal type was " + Short.toString(signalType));
private boolean matchCriterion(OchSignalTypeCriterion criterion) {
final String signalType = criterion.signalType().name();
final String jsonSignalType = jsonCriterion.get("ochSignalType").textValue();
if (!signalType.equals(jsonSignalType)) {
description.appendText("signal type was " + signalType);
return false;
}
return true;
......@@ -575,8 +575,7 @@ public final class CriterionJsonMatcher extends
return matchCriterion((LambdaCriterion) criterion);
case OCH_SIGTYPE:
return matchCriterion(
(OpticalSignalTypeCriterion) criterion);
return matchCriterion((OchSignalTypeCriterion) criterion);
default:
// Don't know how to format this type
......
......@@ -31,11 +31,13 @@ import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.HostId;
import org.onosproject.net.NetTestTools;
import org.onosproject.net.OchSignalType;
import org.onosproject.net.PortNumber;
import org.onosproject.net.flow.DefaultTrafficSelector;
import org.onosproject.net.flow.DefaultTrafficTreatment;
import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.TrafficTreatment;
import org.onosproject.net.flow.criteria.Criteria;
import org.onosproject.net.intent.AbstractIntentTest;
import org.onosproject.net.intent.Constraint;
import org.onosproject.net.intent.HostToHostIntent;
......@@ -139,7 +141,7 @@ public class IntentCodecTest extends AbstractIntentTest {
final TrafficSelector selector = DefaultTrafficSelector.builder()
.matchIPProtocol((byte) 3)
.matchMplsLabel(MplsLabel.mplsLabel(4))
.matchOpticalSignalType((short) 5)
.add(Criteria.matchOchSignalType(OchSignalType.FIXED_GRID))
.matchLambda((short) 6)
.matchEthDst(MacAddress.BROADCAST)
.matchIPDst(IpPrefix.valueOf("1.2.3.4/24"))
......