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

Change-Id: If481573f405d812b0b103e1752a559d8f81d6bd8
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/CriterionCodec.java b/core/common/src/main/java/org/onosproject/codec/impl/CriterionCodec.java
index 3526f23..0421e02 100644
--- a/core/common/src/main/java/org/onosproject/codec/impl/CriterionCodec.java
+++ b/core/common/src/main/java/org/onosproject/codec/impl/CriterionCodec.java
@@ -37,7 +37,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.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 @@
     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());
         }
     }
 
diff --git a/core/common/src/test/java/org/onosproject/codec/impl/CriterionCodecTest.java b/core/common/src/test/java/org/onosproject/codec/impl/CriterionCodecTest.java
index 731f03e..27d691e 100644
--- a/core/common/src/test/java/org/onosproject/codec/impl/CriterionCodecTest.java
+++ b/core/common/src/test/java/org/onosproject/codec/impl/CriterionCodecTest.java
@@ -26,6 +26,7 @@
 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 @@
      */
     @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));
     }
diff --git a/core/common/src/test/java/org/onosproject/codec/impl/CriterionJsonMatcher.java b/core/common/src/test/java/org/onosproject/codec/impl/CriterionJsonMatcher.java
index 6db66e4..40ea708 100644
--- a/core/common/src/test/java/org/onosproject/codec/impl/CriterionJsonMatcher.java
+++ b/core/common/src/test/java/org/onosproject/codec/impl/CriterionJsonMatcher.java
@@ -37,7 +37,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.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 @@
      * @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 @@
                 return matchCriterion((LambdaCriterion) criterion);
 
             case OCH_SIGTYPE:
-                return matchCriterion(
-                        (OpticalSignalTypeCriterion) criterion);
+                return matchCriterion((OchSignalTypeCriterion) criterion);
 
             default:
                 // Don't know how to format this type
diff --git a/core/common/src/test/java/org/onosproject/codec/impl/IntentCodecTest.java b/core/common/src/test/java/org/onosproject/codec/impl/IntentCodecTest.java
index 94a5bda..2c2e488 100644
--- a/core/common/src/test/java/org/onosproject/codec/impl/IntentCodecTest.java
+++ b/core/common/src/test/java/org/onosproject/codec/impl/IntentCodecTest.java
@@ -31,11 +31,13 @@
 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 @@
         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"))