Fix cast error on execution of "flow -j" command
This resolves ONOS-2037. Change-Id: Ie6bf0c7ca0644ae8029df72d3ea7084fa0297aca
Showing
4 changed files
with
47 additions
and
15 deletions
| ... | @@ -19,6 +19,7 @@ import java.util.EnumMap; | ... | @@ -19,6 +19,7 @@ import java.util.EnumMap; |
| 19 | 19 | ||
| 20 | import org.onosproject.codec.CodecContext; | 20 | import org.onosproject.codec.CodecContext; |
| 21 | import org.onosproject.codec.JsonCodec; | 21 | import org.onosproject.codec.JsonCodec; |
| 22 | +import org.onosproject.net.OchSignal; | ||
| 22 | import org.onosproject.net.flow.criteria.Criterion; | 23 | import org.onosproject.net.flow.criteria.Criterion; |
| 23 | import org.onosproject.net.flow.criteria.EthCriterion; | 24 | import org.onosproject.net.flow.criteria.EthCriterion; |
| 24 | import org.onosproject.net.flow.criteria.EthTypeCriterion; | 25 | import org.onosproject.net.flow.criteria.EthTypeCriterion; |
| ... | @@ -34,9 +35,9 @@ import org.onosproject.net.flow.criteria.IcmpCodeCriterion; | ... | @@ -34,9 +35,9 @@ import org.onosproject.net.flow.criteria.IcmpCodeCriterion; |
| 34 | import org.onosproject.net.flow.criteria.IcmpTypeCriterion; | 35 | import org.onosproject.net.flow.criteria.IcmpTypeCriterion; |
| 35 | import org.onosproject.net.flow.criteria.Icmpv6CodeCriterion; | 36 | import org.onosproject.net.flow.criteria.Icmpv6CodeCriterion; |
| 36 | import org.onosproject.net.flow.criteria.Icmpv6TypeCriterion; | 37 | import org.onosproject.net.flow.criteria.Icmpv6TypeCriterion; |
| 37 | -import org.onosproject.net.flow.criteria.LambdaCriterion; | ||
| 38 | import org.onosproject.net.flow.criteria.MetadataCriterion; | 38 | import org.onosproject.net.flow.criteria.MetadataCriterion; |
| 39 | import org.onosproject.net.flow.criteria.MplsCriterion; | 39 | import org.onosproject.net.flow.criteria.MplsCriterion; |
| 40 | +import org.onosproject.net.flow.criteria.OchSignalCriterion; | ||
| 40 | import org.onosproject.net.flow.criteria.OchSignalTypeCriterion; | 41 | import org.onosproject.net.flow.criteria.OchSignalTypeCriterion; |
| 41 | import org.onosproject.net.flow.criteria.PortCriterion; | 42 | import org.onosproject.net.flow.criteria.PortCriterion; |
| 42 | import org.onosproject.net.flow.criteria.SctpPortCriterion; | 43 | import org.onosproject.net.flow.criteria.SctpPortCriterion; |
| ... | @@ -325,9 +326,15 @@ public final class CriterionCodec extends JsonCodec<Criterion> { | ... | @@ -325,9 +326,15 @@ public final class CriterionCodec extends JsonCodec<Criterion> { |
| 325 | private static class FormatOchSigId implements CriterionTypeFormatter { | 326 | private static class FormatOchSigId implements CriterionTypeFormatter { |
| 326 | @Override | 327 | @Override |
| 327 | public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { | 328 | public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { |
| 328 | - final LambdaCriterion lambdaCriterion = | 329 | + OchSignal ochSignal = ((OchSignalCriterion) criterion).lambda(); |
| 329 | - (LambdaCriterion) criterion; | 330 | + ObjectNode child = root.putObject("ochSignalId"); |
| 330 | - return root.put("lambda", lambdaCriterion.lambda()); | 331 | + |
| 332 | + child.put("gridType", ochSignal.gridType().name()); | ||
| 333 | + child.put("channelSpacing", ochSignal.channelSpacing().name()); | ||
| 334 | + child.put("spacingMultiplier", ochSignal.spacingMultiplier()); | ||
| 335 | + child.put("slotGranularity", ochSignal.slotGranularity()); | ||
| 336 | + | ||
| 337 | + return root; | ||
| 331 | } | 338 | } |
| 332 | } | 339 | } |
| 333 | 340 | ... | ... |
| ... | @@ -26,6 +26,9 @@ import org.onlab.packet.MplsLabel; | ... | @@ -26,6 +26,9 @@ import org.onlab.packet.MplsLabel; |
| 26 | import org.onlab.packet.VlanId; | 26 | import org.onlab.packet.VlanId; |
| 27 | import org.onosproject.codec.CodecContext; | 27 | import org.onosproject.codec.CodecContext; |
| 28 | import org.onosproject.codec.JsonCodec; | 28 | import org.onosproject.codec.JsonCodec; |
| 29 | +import org.onosproject.net.ChannelSpacing; | ||
| 30 | +import org.onosproject.net.GridType; | ||
| 31 | +import org.onosproject.net.Lambda; | ||
| 29 | import org.onosproject.net.OchSignalType; | 32 | import org.onosproject.net.OchSignalType; |
| 30 | import org.onosproject.net.PortNumber; | 33 | import org.onosproject.net.PortNumber; |
| 31 | import org.onosproject.net.flow.criteria.Criteria; | 34 | import org.onosproject.net.flow.criteria.Criteria; |
| ... | @@ -406,8 +409,9 @@ public class CriterionCodecTest { | ... | @@ -406,8 +409,9 @@ public class CriterionCodecTest { |
| 406 | * Tests lambda criterion. | 409 | * Tests lambda criterion. |
| 407 | */ | 410 | */ |
| 408 | @Test | 411 | @Test |
| 409 | - public void matchLambdaTest() { | 412 | + public void matchOchSignal() { |
| 410 | - Criterion criterion = Criteria.matchLambda((short) 40000); | 413 | + Lambda ochSignal = Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_100GHZ, 4, 8); |
| 414 | + Criterion criterion = Criteria.matchLambda(ochSignal); | ||
| 411 | ObjectNode result = criterionCodec.encode(criterion, context); | 415 | ObjectNode result = criterionCodec.encode(criterion, context); |
| 412 | assertThat(result, matchesCriterion(criterion)); | 416 | assertThat(result, matchesCriterion(criterion)); |
| 413 | } | 417 | } | ... | ... |
| ... | @@ -15,8 +15,10 @@ | ... | @@ -15,8 +15,10 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.codec.impl; | 16 | package org.onosproject.codec.impl; |
| 17 | 17 | ||
| 18 | +import com.google.common.base.Joiner; | ||
| 18 | import org.hamcrest.Description; | 19 | import org.hamcrest.Description; |
| 19 | import org.hamcrest.TypeSafeDiagnosingMatcher; | 20 | import org.hamcrest.TypeSafeDiagnosingMatcher; |
| 21 | +import org.onosproject.net.OchSignal; | ||
| 20 | import org.onosproject.net.flow.criteria.Criterion; | 22 | import org.onosproject.net.flow.criteria.Criterion; |
| 21 | 23 | ||
| 22 | import com.fasterxml.jackson.databind.JsonNode; | 24 | import com.fasterxml.jackson.databind.JsonNode; |
| ... | @@ -34,9 +36,9 @@ import org.onosproject.net.flow.criteria.IcmpCodeCriterion; | ... | @@ -34,9 +36,9 @@ import org.onosproject.net.flow.criteria.IcmpCodeCriterion; |
| 34 | import org.onosproject.net.flow.criteria.IcmpTypeCriterion; | 36 | import org.onosproject.net.flow.criteria.IcmpTypeCriterion; |
| 35 | import org.onosproject.net.flow.criteria.Icmpv6CodeCriterion; | 37 | import org.onosproject.net.flow.criteria.Icmpv6CodeCriterion; |
| 36 | import org.onosproject.net.flow.criteria.Icmpv6TypeCriterion; | 38 | import org.onosproject.net.flow.criteria.Icmpv6TypeCriterion; |
| 37 | -import org.onosproject.net.flow.criteria.LambdaCriterion; | ||
| 38 | import org.onosproject.net.flow.criteria.MetadataCriterion; | 39 | import org.onosproject.net.flow.criteria.MetadataCriterion; |
| 39 | import org.onosproject.net.flow.criteria.MplsCriterion; | 40 | import org.onosproject.net.flow.criteria.MplsCriterion; |
| 41 | +import org.onosproject.net.flow.criteria.OchSignalCriterion; | ||
| 40 | import org.onosproject.net.flow.criteria.OchSignalTypeCriterion; | 42 | import org.onosproject.net.flow.criteria.OchSignalTypeCriterion; |
| 41 | import org.onosproject.net.flow.criteria.PortCriterion; | 43 | import org.onosproject.net.flow.criteria.PortCriterion; |
| 42 | import org.onosproject.net.flow.criteria.SctpPortCriterion; | 44 | import org.onosproject.net.flow.criteria.SctpPortCriterion; |
| ... | @@ -45,6 +47,8 @@ import org.onosproject.net.flow.criteria.UdpPortCriterion; | ... | @@ -45,6 +47,8 @@ import org.onosproject.net.flow.criteria.UdpPortCriterion; |
| 45 | import org.onosproject.net.flow.criteria.VlanIdCriterion; | 47 | import org.onosproject.net.flow.criteria.VlanIdCriterion; |
| 46 | import org.onosproject.net.flow.criteria.VlanPcpCriterion; | 48 | import org.onosproject.net.flow.criteria.VlanPcpCriterion; |
| 47 | 49 | ||
| 50 | +import java.util.Objects; | ||
| 51 | + | ||
| 48 | /** | 52 | /** |
| 49 | * Hamcrest matcher for criterion objects. | 53 | * Hamcrest matcher for criterion objects. |
| 50 | */ | 54 | */ |
| ... | @@ -448,16 +452,29 @@ public final class CriterionJsonMatcher extends | ... | @@ -448,16 +452,29 @@ public final class CriterionJsonMatcher extends |
| 448 | } | 452 | } |
| 449 | 453 | ||
| 450 | /** | 454 | /** |
| 451 | - * Matches a lambda criterion object. | 455 | + * Matches an Och signal criterion object. |
| 452 | * | 456 | * |
| 453 | * @param criterion criterion to match | 457 | * @param criterion criterion to match |
| 454 | * @return true if the JSON matches the criterion, false otherwise. | 458 | * @return true if the JSON matches the criterion, false otherwise. |
| 455 | */ | 459 | */ |
| 456 | - private boolean matchCriterion(LambdaCriterion criterion) { | 460 | + private boolean matchCriterion(OchSignalCriterion criterion) { |
| 457 | - final int lambda = criterion.lambda(); | 461 | + final OchSignal ochSignal = criterion.lambda(); |
| 458 | - final int jsonLambda = jsonCriterion.get("lambda").intValue(); | 462 | + final JsonNode jsonOchSignal = jsonCriterion.get("ochSignalId"); |
| 459 | - if (lambda != jsonLambda) { | 463 | + String jsonGridType = jsonOchSignal.get("gridType").textValue(); |
| 460 | - description.appendText("lambda was " + Integer.toString(lambda)); | 464 | + String jsonChannelSpacing = jsonOchSignal.get("channelSpacing").textValue(); |
| 465 | + int jsonSpacingMultiplier = jsonOchSignal.get("spacingMultiplier").intValue(); | ||
| 466 | + int jsonSlotGranularity = jsonOchSignal.get("slotGranularity").intValue(); | ||
| 467 | + | ||
| 468 | + boolean equality = Objects.equals(ochSignal.gridType().name(), jsonGridType) | ||
| 469 | + && Objects.equals(ochSignal.channelSpacing().name(), jsonChannelSpacing) | ||
| 470 | + && Objects.equals(ochSignal.spacingMultiplier(), jsonSpacingMultiplier) | ||
| 471 | + && Objects.equals(ochSignal.slotGranularity(), jsonSlotGranularity); | ||
| 472 | + | ||
| 473 | + if (!equality) { | ||
| 474 | + String joined = Joiner.on(", ") | ||
| 475 | + .join(jsonGridType, jsonChannelSpacing, jsonSpacingMultiplier, jsonSlotGranularity); | ||
| 476 | + | ||
| 477 | + description.appendText("och signal id was " + joined); | ||
| 461 | return false; | 478 | return false; |
| 462 | } | 479 | } |
| 463 | return true; | 480 | return true; |
| ... | @@ -572,7 +589,7 @@ public final class CriterionJsonMatcher extends | ... | @@ -572,7 +589,7 @@ public final class CriterionJsonMatcher extends |
| 572 | (IPv6ExthdrFlagsCriterion) criterion); | 589 | (IPv6ExthdrFlagsCriterion) criterion); |
| 573 | 590 | ||
| 574 | case OCH_SIGID: | 591 | case OCH_SIGID: |
| 575 | - return matchCriterion((LambdaCriterion) criterion); | 592 | + return matchCriterion((OchSignalCriterion) criterion); |
| 576 | 593 | ||
| 577 | case OCH_SIGTYPE: | 594 | case OCH_SIGTYPE: |
| 578 | return matchCriterion((OchSignalTypeCriterion) criterion); | 595 | return matchCriterion((OchSignalTypeCriterion) criterion); | ... | ... |
| ... | @@ -27,9 +27,12 @@ import org.onlab.util.Bandwidth; | ... | @@ -27,9 +27,12 @@ import org.onlab.util.Bandwidth; |
| 27 | import org.onosproject.codec.JsonCodec; | 27 | import org.onosproject.codec.JsonCodec; |
| 28 | import org.onosproject.core.ApplicationId; | 28 | import org.onosproject.core.ApplicationId; |
| 29 | import org.onosproject.core.DefaultApplicationId; | 29 | import org.onosproject.core.DefaultApplicationId; |
| 30 | +import org.onosproject.net.ChannelSpacing; | ||
| 30 | import org.onosproject.net.ConnectPoint; | 31 | import org.onosproject.net.ConnectPoint; |
| 31 | import org.onosproject.net.DeviceId; | 32 | import org.onosproject.net.DeviceId; |
| 33 | +import org.onosproject.net.GridType; | ||
| 32 | import org.onosproject.net.HostId; | 34 | import org.onosproject.net.HostId; |
| 35 | +import org.onosproject.net.Lambda; | ||
| 33 | import org.onosproject.net.NetTestTools; | 36 | import org.onosproject.net.NetTestTools; |
| 34 | import org.onosproject.net.OchSignalType; | 37 | import org.onosproject.net.OchSignalType; |
| 35 | import org.onosproject.net.PortNumber; | 38 | import org.onosproject.net.PortNumber; |
| ... | @@ -138,11 +141,12 @@ public class IntentCodecTest extends AbstractIntentTest { | ... | @@ -138,11 +141,12 @@ public class IntentCodecTest extends AbstractIntentTest { |
| 138 | DeviceId did1 = did("device1"); | 141 | DeviceId did1 = did("device1"); |
| 139 | DeviceId did2 = did("device2"); | 142 | DeviceId did2 = did("device2"); |
| 140 | DeviceId did3 = did("device3"); | 143 | DeviceId did3 = did("device3"); |
| 144 | + Lambda ochSignal = Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_100GHZ, 4, 8); | ||
| 141 | final TrafficSelector selector = DefaultTrafficSelector.builder() | 145 | final TrafficSelector selector = DefaultTrafficSelector.builder() |
| 142 | .matchIPProtocol((byte) 3) | 146 | .matchIPProtocol((byte) 3) |
| 143 | .matchMplsLabel(MplsLabel.mplsLabel(4)) | 147 | .matchMplsLabel(MplsLabel.mplsLabel(4)) |
| 144 | .add(Criteria.matchOchSignalType(OchSignalType.FIXED_GRID)) | 148 | .add(Criteria.matchOchSignalType(OchSignalType.FIXED_GRID)) |
| 145 | - .matchLambda((short) 6) | 149 | + .add(Criteria.matchLambda(ochSignal)) |
| 146 | .matchEthDst(MacAddress.BROADCAST) | 150 | .matchEthDst(MacAddress.BROADCAST) |
| 147 | .matchIPDst(IpPrefix.valueOf("1.2.3.4/24")) | 151 | .matchIPDst(IpPrefix.valueOf("1.2.3.4/24")) |
| 148 | .build(); | 152 | .build(); | ... | ... |
-
Please register or login to post a comment