Committed by
Gerrit Code Review
Fix a cast error when creating OpticalConnectivityIntent
A cast error occurred in FlowModBuilder when the type of Criterion was OCH_SIGID. Move two convertion methods from FlowModBuilderVer13 to FlowModBuilderHelper for refactoring. Change-Id: I4634d57fc70cfb144de64d72140cbca81e060248
Showing
3 changed files
with
106 additions
and
49 deletions
| ... | @@ -20,6 +20,7 @@ import org.onlab.packet.Ip4Prefix; | ... | @@ -20,6 +20,7 @@ import org.onlab.packet.Ip4Prefix; |
| 20 | import org.onlab.packet.Ip6Address; | 20 | import org.onlab.packet.Ip6Address; |
| 21 | import org.onlab.packet.Ip6Prefix; | 21 | import org.onlab.packet.Ip6Prefix; |
| 22 | import org.onlab.packet.VlanId; | 22 | import org.onlab.packet.VlanId; |
| 23 | +import org.onosproject.net.OchSignal; | ||
| 23 | import org.onosproject.net.flow.FlowRule; | 24 | import org.onosproject.net.flow.FlowRule; |
| 24 | import org.onosproject.net.flow.TrafficSelector; | 25 | import org.onosproject.net.flow.TrafficSelector; |
| 25 | import org.onosproject.net.flow.criteria.EthCriterion; | 26 | import org.onosproject.net.flow.criteria.EthCriterion; |
| ... | @@ -36,9 +37,9 @@ import org.onosproject.net.flow.criteria.IcmpCodeCriterion; | ... | @@ -36,9 +37,9 @@ import org.onosproject.net.flow.criteria.IcmpCodeCriterion; |
| 36 | import org.onosproject.net.flow.criteria.IcmpTypeCriterion; | 37 | import org.onosproject.net.flow.criteria.IcmpTypeCriterion; |
| 37 | import org.onosproject.net.flow.criteria.Icmpv6CodeCriterion; | 38 | import org.onosproject.net.flow.criteria.Icmpv6CodeCriterion; |
| 38 | import org.onosproject.net.flow.criteria.Icmpv6TypeCriterion; | 39 | import org.onosproject.net.flow.criteria.Icmpv6TypeCriterion; |
| 39 | -import org.onosproject.net.flow.criteria.LambdaCriterion; | ||
| 40 | import org.onosproject.net.flow.criteria.MetadataCriterion; | 40 | import org.onosproject.net.flow.criteria.MetadataCriterion; |
| 41 | import org.onosproject.net.flow.criteria.MplsCriterion; | 41 | import org.onosproject.net.flow.criteria.MplsCriterion; |
| 42 | +import org.onosproject.net.flow.criteria.OchSignalCriterion; | ||
| 42 | import org.onosproject.net.flow.criteria.OpticalSignalTypeCriterion; | 43 | import org.onosproject.net.flow.criteria.OpticalSignalTypeCriterion; |
| 43 | import org.onosproject.net.flow.criteria.PortCriterion; | 44 | import org.onosproject.net.flow.criteria.PortCriterion; |
| 44 | import org.onosproject.net.flow.criteria.SctpPortCriterion; | 45 | import org.onosproject.net.flow.criteria.SctpPortCriterion; |
| ... | @@ -374,10 +375,17 @@ public abstract class FlowModBuilder { | ... | @@ -374,10 +375,17 @@ public abstract class FlowModBuilder { |
| 374 | U16.of(exthdrFlagsCriterion.exthdrFlags())); | 375 | U16.of(exthdrFlagsCriterion.exthdrFlags())); |
| 375 | break; | 376 | break; |
| 376 | case OCH_SIGID: | 377 | case OCH_SIGID: |
| 377 | - LambdaCriterion lc = (LambdaCriterion) c; | 378 | + try { |
| 378 | - mBuilder.setExact(MatchField.OCH_SIGID, | 379 | + OchSignalCriterion ochSignalCriterion = (OchSignalCriterion) c; |
| 379 | - new CircuitSignalID((byte) 1, (byte) 2, | 380 | + OchSignal signal = ochSignalCriterion.lambda(); |
| 380 | - (short) lc.lambda(), (short) 1)); | 381 | + byte gridType = FlowModBuilderHelper.convertGridType(signal.gridType()); |
| 382 | + byte channelSpacing = FlowModBuilderHelper.convertChannelSpacing(signal.channelSpacing()); | ||
| 383 | + mBuilder.setExact(MatchField.OCH_SIGID, | ||
| 384 | + new CircuitSignalID(gridType, channelSpacing, | ||
| 385 | + (short) signal.spacingMultiplier(), (short) signal.slotGranularity())); | ||
| 386 | + } catch (UnsupportedGridTypeException | UnsupportedChannelSpacingException e) { | ||
| 387 | + log.warn(e.getMessage()); | ||
| 388 | + } | ||
| 381 | break; | 389 | break; |
| 382 | case OCH_SIGTYPE: | 390 | case OCH_SIGTYPE: |
| 383 | OpticalSignalTypeCriterion sc = | 391 | OpticalSignalTypeCriterion sc = | ... | ... |
| 1 | +/* | ||
| 2 | + * Copyright 2015 Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.provider.of.flow.impl; | ||
| 17 | + | ||
| 18 | +import org.onosproject.net.ChannelSpacing; | ||
| 19 | +import org.onosproject.net.GridType; | ||
| 20 | +import org.slf4j.Logger; | ||
| 21 | +import org.slf4j.LoggerFactory; | ||
| 22 | + | ||
| 23 | +/** | ||
| 24 | + * Collection of helper methods to convert protocol agnostic models to values used in OpenFlow spec. | ||
| 25 | + */ | ||
| 26 | +final class FlowModBuilderHelper { | ||
| 27 | + | ||
| 28 | + private static final Logger log = LoggerFactory.getLogger(FlowModBuilderHelper.class); | ||
| 29 | + | ||
| 30 | + // prohibit instantiation | ||
| 31 | + private FlowModBuilderHelper() {} | ||
| 32 | + | ||
| 33 | + /** | ||
| 34 | + * Converts a {@link GridType} to the corresponding byte value defined in | ||
| 35 | + * ONF "Optical Transport Protocol Extensions Version 1.0". | ||
| 36 | + * | ||
| 37 | + * @param type grid type | ||
| 38 | + * @return the byte value corresponding to the specified grid type | ||
| 39 | + * @throws UnsupportedGridTypeException if the specified grid type is not supported | ||
| 40 | + */ | ||
| 41 | + static byte convertGridType(GridType type) { | ||
| 42 | + // See ONF "Optical Transport Protocol Extensions Version 1.0" | ||
| 43 | + // for the following values | ||
| 44 | + switch (type) { | ||
| 45 | + case DWDM: | ||
| 46 | + // OFPGRIDT_DWDM of enum ofp_grid_type | ||
| 47 | + return 1; | ||
| 48 | + case CWDM: | ||
| 49 | + // OFPGRIDT_CWDM of enum ofp_grid_type | ||
| 50 | + return 2; | ||
| 51 | + case FLEX: | ||
| 52 | + // OFPGRIDT_FLEX of enum ofp_grid_type | ||
| 53 | + return 3; | ||
| 54 | + default: | ||
| 55 | + throw new UnsupportedGridTypeException(type); | ||
| 56 | + } | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + /** | ||
| 60 | + * Converts a {@link ChannelSpacing} to the corresponding byte value defined in | ||
| 61 | + * ONF "Optical Transport Protocol Extensions Version 1.0". | ||
| 62 | + * | ||
| 63 | + * @param spacing channel spacing | ||
| 64 | + * @return byte value corresponding to the specified channel spacing | ||
| 65 | + * @throws UnsupportedChannelSpacingException if the specified channel spacing is not supported | ||
| 66 | + */ | ||
| 67 | + static byte convertChannelSpacing(ChannelSpacing spacing) { | ||
| 68 | + // See ONF "Optical Transport Protocol Extensions Version 1.0" | ||
| 69 | + // for the following values | ||
| 70 | + switch (spacing) { | ||
| 71 | + case CHL_100GHZ: | ||
| 72 | + // OFPCS_100GHZ of enum ofp_chl_spacing | ||
| 73 | + return 1; | ||
| 74 | + case CHL_50GHZ: | ||
| 75 | + // OFPCS_50GHZ of enum ofp_chl_spacing | ||
| 76 | + return 2; | ||
| 77 | + case CHL_25GHZ: | ||
| 78 | + // OFPCS_25GHZ of enum ofp_chl_spacing | ||
| 79 | + return 3; | ||
| 80 | + case CHL_12P5GHZ: | ||
| 81 | + // OFPCS_12P5GHZ of enum ofp_chl_spacing | ||
| 82 | + return 4; | ||
| 83 | + case CHL_6P25GHZ: | ||
| 84 | + // OFPCS_6P25GHZ of enum ofp_chl_spacing | ||
| 85 | + return 5; | ||
| 86 | + default: | ||
| 87 | + throw new UnsupportedChannelSpacingException(spacing); | ||
| 88 | + } | ||
| 89 | + } | ||
| 90 | +} |
providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowModBuilderVer13.java
| ... | @@ -18,8 +18,6 @@ package org.onosproject.provider.of.flow.impl; | ... | @@ -18,8 +18,6 @@ package org.onosproject.provider.of.flow.impl; |
| 18 | import com.google.common.collect.Lists; | 18 | import com.google.common.collect.Lists; |
| 19 | import org.onlab.packet.Ip4Address; | 19 | import org.onlab.packet.Ip4Address; |
| 20 | import org.onlab.packet.Ip6Address; | 20 | import org.onlab.packet.Ip6Address; |
| 21 | -import org.onosproject.net.ChannelSpacing; | ||
| 22 | -import org.onosproject.net.GridType; | ||
| 23 | import org.onosproject.net.OchSignal; | 21 | import org.onosproject.net.OchSignal; |
| 24 | import org.onosproject.net.PortNumber; | 22 | import org.onosproject.net.PortNumber; |
| 25 | import org.onosproject.net.flow.FlowRule; | 23 | import org.onosproject.net.flow.FlowRule; |
| ... | @@ -73,6 +71,9 @@ import java.util.LinkedList; | ... | @@ -73,6 +71,9 @@ import java.util.LinkedList; |
| 73 | import java.util.List; | 71 | import java.util.List; |
| 74 | import java.util.Optional; | 72 | import java.util.Optional; |
| 75 | 73 | ||
| 74 | +import static org.onosproject.provider.of.flow.impl.FlowModBuilderHelper.convertChannelSpacing; | ||
| 75 | +import static org.onosproject.provider.of.flow.impl.FlowModBuilderHelper.convertGridType; | ||
| 76 | + | ||
| 76 | /** | 77 | /** |
| 77 | * Flow mod builder for OpenFlow 1.3+. | 78 | * Flow mod builder for OpenFlow 1.3+. |
| 78 | */ | 79 | */ |
| ... | @@ -281,48 +282,6 @@ public class FlowModBuilderVer13 extends FlowModBuilder { | ... | @@ -281,48 +282,6 @@ public class FlowModBuilderVer13 extends FlowModBuilder { |
| 281 | )); | 282 | )); |
| 282 | } | 283 | } |
| 283 | 284 | ||
| 284 | - private byte convertGridType(GridType type) { | ||
| 285 | - // See ONF "Optical Transport Protocol Extensions Version 1.0" | ||
| 286 | - // for the following values | ||
| 287 | - switch (type) { | ||
| 288 | - case DWDM: | ||
| 289 | - // OFPGRIDT_DWDM of enum ofp_grid_type | ||
| 290 | - return 1; | ||
| 291 | - case CWDM: | ||
| 292 | - // OFPGRIDT_CWDM of enum ofp_grid_type | ||
| 293 | - return 2; | ||
| 294 | - case FLEX: | ||
| 295 | - // OFPGRIDT_FLEX of enum ofp_grid_type | ||
| 296 | - return 3; | ||
| 297 | - default: | ||
| 298 | - throw new UnsupportedGridTypeException(type); | ||
| 299 | - } | ||
| 300 | - } | ||
| 301 | - | ||
| 302 | - private byte convertChannelSpacing(ChannelSpacing spacing) { | ||
| 303 | - // See ONF "Optical Transport Protocol Extensions Version 1.0" | ||
| 304 | - // for the following values | ||
| 305 | - switch (spacing) { | ||
| 306 | - case CHL_100GHZ: | ||
| 307 | - // OFPCS_100GHZ of enum ofp_chl_spacing | ||
| 308 | - return 1; | ||
| 309 | - case CHL_50GHZ: | ||
| 310 | - // OFPCS_50GHZ of enum ofp_chl_spacing | ||
| 311 | - return 2; | ||
| 312 | - case CHL_25GHZ: | ||
| 313 | - // OFPCS_25GHZ of enum ofp_chl_spacing | ||
| 314 | - return 3; | ||
| 315 | - case CHL_12P5GHZ: | ||
| 316 | - // OFPCS_12P5GHZ of enum ofp_chl_spacing | ||
| 317 | - return 4; | ||
| 318 | - case CHL_6P25GHZ: | ||
| 319 | - // OFPCS_6P25GHZ of enum ofp_chl_spacing | ||
| 320 | - return 5; | ||
| 321 | - default: | ||
| 322 | - throw new UnsupportedChannelSpacingException(spacing); | ||
| 323 | - } | ||
| 324 | - } | ||
| 325 | - | ||
| 326 | private OFAction buildL2Modification(Instruction i) { | 285 | private OFAction buildL2Modification(Instruction i) { |
| 327 | L2ModificationInstruction l2m = (L2ModificationInstruction) i; | 286 | L2ModificationInstruction l2m = (L2ModificationInstruction) i; |
| 328 | ModEtherInstruction eth; | 287 | ModEtherInstruction eth; | ... | ... |
-
Please register or login to post a comment