Sho SHIMIZU
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
......@@ -20,6 +20,7 @@ import org.onlab.packet.Ip4Prefix;
import org.onlab.packet.Ip6Address;
import org.onlab.packet.Ip6Prefix;
import org.onlab.packet.VlanId;
import org.onosproject.net.OchSignal;
import org.onosproject.net.flow.FlowRule;
import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.criteria.EthCriterion;
......@@ -36,9 +37,9 @@ import org.onosproject.net.flow.criteria.IcmpCodeCriterion;
import org.onosproject.net.flow.criteria.IcmpTypeCriterion;
import org.onosproject.net.flow.criteria.Icmpv6CodeCriterion;
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.OchSignalCriterion;
import org.onosproject.net.flow.criteria.OpticalSignalTypeCriterion;
import org.onosproject.net.flow.criteria.PortCriterion;
import org.onosproject.net.flow.criteria.SctpPortCriterion;
......@@ -374,10 +375,17 @@ public abstract class FlowModBuilder {
U16.of(exthdrFlagsCriterion.exthdrFlags()));
break;
case OCH_SIGID:
LambdaCriterion lc = (LambdaCriterion) c;
mBuilder.setExact(MatchField.OCH_SIGID,
new CircuitSignalID((byte) 1, (byte) 2,
(short) lc.lambda(), (short) 1));
try {
OchSignalCriterion ochSignalCriterion = (OchSignalCriterion) c;
OchSignal signal = ochSignalCriterion.lambda();
byte gridType = FlowModBuilderHelper.convertGridType(signal.gridType());
byte channelSpacing = FlowModBuilderHelper.convertChannelSpacing(signal.channelSpacing());
mBuilder.setExact(MatchField.OCH_SIGID,
new CircuitSignalID(gridType, channelSpacing,
(short) signal.spacingMultiplier(), (short) signal.slotGranularity()));
} catch (UnsupportedGridTypeException | UnsupportedChannelSpacingException e) {
log.warn(e.getMessage());
}
break;
case OCH_SIGTYPE:
OpticalSignalTypeCriterion sc =
......
/*
* 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.provider.of.flow.impl;
import org.onosproject.net.ChannelSpacing;
import org.onosproject.net.GridType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Collection of helper methods to convert protocol agnostic models to values used in OpenFlow spec.
*/
final class FlowModBuilderHelper {
private static final Logger log = LoggerFactory.getLogger(FlowModBuilderHelper.class);
// prohibit instantiation
private FlowModBuilderHelper() {}
/**
* Converts a {@link GridType} to the corresponding byte value defined in
* ONF "Optical Transport Protocol Extensions Version 1.0".
*
* @param type grid type
* @return the byte value corresponding to the specified grid type
* @throws UnsupportedGridTypeException if the specified grid type is not supported
*/
static byte convertGridType(GridType type) {
// See ONF "Optical Transport Protocol Extensions Version 1.0"
// for the following values
switch (type) {
case DWDM:
// OFPGRIDT_DWDM of enum ofp_grid_type
return 1;
case CWDM:
// OFPGRIDT_CWDM of enum ofp_grid_type
return 2;
case FLEX:
// OFPGRIDT_FLEX of enum ofp_grid_type
return 3;
default:
throw new UnsupportedGridTypeException(type);
}
}
/**
* Converts a {@link ChannelSpacing} to the corresponding byte value defined in
* ONF "Optical Transport Protocol Extensions Version 1.0".
*
* @param spacing channel spacing
* @return byte value corresponding to the specified channel spacing
* @throws UnsupportedChannelSpacingException if the specified channel spacing is not supported
*/
static byte convertChannelSpacing(ChannelSpacing spacing) {
// See ONF "Optical Transport Protocol Extensions Version 1.0"
// for the following values
switch (spacing) {
case CHL_100GHZ:
// OFPCS_100GHZ of enum ofp_chl_spacing
return 1;
case CHL_50GHZ:
// OFPCS_50GHZ of enum ofp_chl_spacing
return 2;
case CHL_25GHZ:
// OFPCS_25GHZ of enum ofp_chl_spacing
return 3;
case CHL_12P5GHZ:
// OFPCS_12P5GHZ of enum ofp_chl_spacing
return 4;
case CHL_6P25GHZ:
// OFPCS_6P25GHZ of enum ofp_chl_spacing
return 5;
default:
throw new UnsupportedChannelSpacingException(spacing);
}
}
}
......@@ -18,8 +18,6 @@ package org.onosproject.provider.of.flow.impl;
import com.google.common.collect.Lists;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.Ip6Address;
import org.onosproject.net.ChannelSpacing;
import org.onosproject.net.GridType;
import org.onosproject.net.OchSignal;
import org.onosproject.net.PortNumber;
import org.onosproject.net.flow.FlowRule;
......@@ -73,6 +71,9 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import static org.onosproject.provider.of.flow.impl.FlowModBuilderHelper.convertChannelSpacing;
import static org.onosproject.provider.of.flow.impl.FlowModBuilderHelper.convertGridType;
/**
* Flow mod builder for OpenFlow 1.3+.
*/
......@@ -281,48 +282,6 @@ public class FlowModBuilderVer13 extends FlowModBuilder {
));
}
private byte convertGridType(GridType type) {
// See ONF "Optical Transport Protocol Extensions Version 1.0"
// for the following values
switch (type) {
case DWDM:
// OFPGRIDT_DWDM of enum ofp_grid_type
return 1;
case CWDM:
// OFPGRIDT_CWDM of enum ofp_grid_type
return 2;
case FLEX:
// OFPGRIDT_FLEX of enum ofp_grid_type
return 3;
default:
throw new UnsupportedGridTypeException(type);
}
}
private byte convertChannelSpacing(ChannelSpacing spacing) {
// See ONF "Optical Transport Protocol Extensions Version 1.0"
// for the following values
switch (spacing) {
case CHL_100GHZ:
// OFPCS_100GHZ of enum ofp_chl_spacing
return 1;
case CHL_50GHZ:
// OFPCS_50GHZ of enum ofp_chl_spacing
return 2;
case CHL_25GHZ:
// OFPCS_25GHZ of enum ofp_chl_spacing
return 3;
case CHL_12P5GHZ:
// OFPCS_12P5GHZ of enum ofp_chl_spacing
return 4;
case CHL_6P25GHZ:
// OFPCS_6P25GHZ of enum ofp_chl_spacing
return 5;
default:
throw new UnsupportedChannelSpacingException(spacing);
}
}
private OFAction buildL2Modification(Instruction i) {
L2ModificationInstruction l2m = (L2ModificationInstruction) i;
ModEtherInstruction eth;
......