Sho SHIMIZU
Committed by Thomas Vachuska

Refactor: Rename the class and method to make them more descriptive

- Rename from FlowModBuilderHelper to OpenFlowValueMapper
- Rename from UnsupportedConversionException to NoMappingFoundException
- For methods, use "lookup" instead of "convert"

Change-Id: I8e86e3221385a48524247aa78a497b524e16071a
...@@ -79,9 +79,9 @@ import java.util.List; ...@@ -79,9 +79,9 @@ import java.util.List;
79 79
80 import static org.onosproject.net.flow.criteria.Criteria.matchLambda; 80 import static org.onosproject.net.flow.criteria.Criteria.matchLambda;
81 import static org.onosproject.net.flow.criteria.Criteria.matchOchSignalType; 81 import static org.onosproject.net.flow.criteria.Criteria.matchOchSignalType;
82 -import static org.onosproject.provider.of.flow.impl.FlowModBuilderHelper.convertChannelSpacing; 82 +import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupChannelSpacing;
83 -import static org.onosproject.provider.of.flow.impl.FlowModBuilderHelper.convertGridType; 83 +import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupGridType;
84 -import static org.onosproject.provider.of.flow.impl.FlowModBuilderHelper.convertOchSignalType; 84 +import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupOchSignalType;
85 import static org.slf4j.LoggerFactory.getLogger; 85 import static org.slf4j.LoggerFactory.getLogger;
86 86
87 public class FlowEntryBuilder { 87 public class FlowEntryBuilder {
...@@ -643,13 +643,13 @@ public class FlowEntryBuilder { ...@@ -643,13 +643,13 @@ public class FlowEntryBuilder {
643 case OCH_SIGID: 643 case OCH_SIGID:
644 CircuitSignalID sigId = match.get(MatchField.OCH_SIGID); 644 CircuitSignalID sigId = match.get(MatchField.OCH_SIGID);
645 builder.add(matchLambda(Lambda.ochSignal( 645 builder.add(matchLambda(Lambda.ochSignal(
646 - convertGridType(sigId.getGridType()), convertChannelSpacing(sigId.getChannelSpacing()), 646 + lookupGridType(sigId.getGridType()), lookupChannelSpacing(sigId.getChannelSpacing()),
647 sigId.getChannelNumber(), sigId.getChannelSpacing()) 647 sigId.getChannelNumber(), sigId.getChannelSpacing())
648 )); 648 ));
649 break; 649 break;
650 case OCH_SIGTYPE: 650 case OCH_SIGTYPE:
651 U8 sigType = match.get(MatchField.OCH_SIGTYPE); 651 U8 sigType = match.get(MatchField.OCH_SIGTYPE);
652 - builder.add(matchOchSignalType(convertOchSignalType((byte) sigType.getValue()))); 652 + builder.add(matchOchSignalType(lookupOchSignalType((byte) sigType.getValue())));
653 break; 653 break;
654 case ARP_OP: 654 case ARP_OP:
655 case ARP_SHA: 655 case ARP_SHA:
......
...@@ -378,18 +378,18 @@ public abstract class FlowModBuilder { ...@@ -378,18 +378,18 @@ public abstract class FlowModBuilder {
378 try { 378 try {
379 OchSignalCriterion ochSignalCriterion = (OchSignalCriterion) c; 379 OchSignalCriterion ochSignalCriterion = (OchSignalCriterion) c;
380 OchSignal signal = ochSignalCriterion.lambda(); 380 OchSignal signal = ochSignalCriterion.lambda();
381 - byte gridType = FlowModBuilderHelper.convertGridType(signal.gridType()); 381 + byte gridType = OpenFlowValueMapper.lookupGridType(signal.gridType());
382 - byte channelSpacing = FlowModBuilderHelper.convertChannelSpacing(signal.channelSpacing()); 382 + byte channelSpacing = OpenFlowValueMapper.lookupChannelSpacing(signal.channelSpacing());
383 mBuilder.setExact(MatchField.OCH_SIGID, 383 mBuilder.setExact(MatchField.OCH_SIGID,
384 new CircuitSignalID(gridType, channelSpacing, 384 new CircuitSignalID(gridType, channelSpacing,
385 (short) signal.spacingMultiplier(), (short) signal.slotGranularity())); 385 (short) signal.spacingMultiplier(), (short) signal.slotGranularity()));
386 - } catch (UnsupportedConversionException e) { 386 + } catch (NoMappingFoundException e) {
387 log.warn(e.getMessage()); 387 log.warn(e.getMessage());
388 } 388 }
389 break; 389 break;
390 case OCH_SIGTYPE: 390 case OCH_SIGTYPE:
391 OchSignalTypeCriterion sc = (OchSignalTypeCriterion) c; 391 OchSignalTypeCriterion sc = (OchSignalTypeCriterion) c;
392 - byte signalType = FlowModBuilderHelper.convertOchSignalType(sc.signalType()); 392 + byte signalType = OpenFlowValueMapper.lookupOchSignalType(sc.signalType());
393 mBuilder.setExact(MatchField.OCH_SIGTYPE, U8.of(signalType)); 393 mBuilder.setExact(MatchField.OCH_SIGTYPE, U8.of(signalType));
394 break; 394 break;
395 case ARP_OP: 395 case ARP_OP:
......
...@@ -71,9 +71,6 @@ import java.util.LinkedList; ...@@ -71,9 +71,6 @@ import java.util.LinkedList;
71 import java.util.List; 71 import java.util.List;
72 import java.util.Optional; 72 import java.util.Optional;
73 73
74 -import static org.onosproject.provider.of.flow.impl.FlowModBuilderHelper.convertChannelSpacing;
75 -import static org.onosproject.provider.of.flow.impl.FlowModBuilderHelper.convertGridType;
76 -
77 /** 74 /**
78 * Flow mod builder for OpenFlow 1.3+. 75 * Flow mod builder for OpenFlow 1.3+.
79 */ 76 */
...@@ -267,7 +264,7 @@ public class FlowModBuilderVer13 extends FlowModBuilder { ...@@ -267,7 +264,7 @@ public class FlowModBuilderVer13 extends FlowModBuilder {
267 case OCH: 264 case OCH:
268 try { 265 try {
269 return buildModOchSignalInstruction((ModOchSignalInstruction) i); 266 return buildModOchSignalInstruction((ModOchSignalInstruction) i);
270 - } catch (UnsupportedConversionException e) { 267 + } catch (NoMappingFoundException e) {
271 log.warn(e.getMessage()); 268 log.warn(e.getMessage());
272 break; 269 break;
273 } 270 }
...@@ -285,8 +282,8 @@ public class FlowModBuilderVer13 extends FlowModBuilder { ...@@ -285,8 +282,8 @@ public class FlowModBuilderVer13 extends FlowModBuilder {
285 282
286 private OFAction buildModOchSignalInstruction(ModOchSignalInstruction instruction) { 283 private OFAction buildModOchSignalInstruction(ModOchSignalInstruction instruction) {
287 OchSignal signal = instruction.lambda(); 284 OchSignal signal = instruction.lambda();
288 - byte gridType = convertGridType(signal.gridType()); 285 + byte gridType = OpenFlowValueMapper.lookupGridType(signal.gridType());
289 - byte channelSpacing = convertChannelSpacing(signal.channelSpacing()); 286 + byte channelSpacing = OpenFlowValueMapper.lookupChannelSpacing(signal.channelSpacing());
290 287
291 return factory().actions().circuit(factory().oxms().ochSigidBasic( 288 return factory().actions().circuit(factory().oxms().ochSigidBasic(
292 new CircuitSignalID(gridType, channelSpacing, 289 new CircuitSignalID(gridType, channelSpacing,
......
...@@ -16,16 +16,16 @@ ...@@ -16,16 +16,16 @@
16 package org.onosproject.provider.of.flow.impl; 16 package org.onosproject.provider.of.flow.impl;
17 17
18 /** 18 /**
19 - * Thrown to indicate that unsupported conversion occurs. 19 + * Thrown to indicate that no mapping for the input value is found.
20 */ 20 */
21 -public class UnsupportedConversionException extends RuntimeException { 21 +public class NoMappingFoundException extends RuntimeException {
22 /** 22 /**
23 * Creates an instance with the specified values. 23 * Creates an instance with the specified values.
24 * 24 *
25 - * @param input input value of conversion causing this exception 25 + * @param input input value of mapping causing this exception
26 - * @param output the desired class which the input value is converted to 26 + * @param output the desired class which the input value is mapped to
27 */ 27 */
28 - public UnsupportedConversionException(Object input, Class<?> output) { 28 + public NoMappingFoundException(Object input, Class<?> output) {
29 super(String.format("No mapping found for %s when converting to %s", input, output.getName())); 29 super(String.format("No mapping found for %s when converting to %s", input, output.getName()));
30 } 30 }
31 } 31 }
......
...@@ -24,11 +24,10 @@ import org.onosproject.net.OchSignalType; ...@@ -24,11 +24,10 @@ import org.onosproject.net.OchSignalType;
24 /** 24 /**
25 * Collection of helper methods to convert protocol agnostic models to values used in OpenFlow spec. 25 * Collection of helper methods to convert protocol agnostic models to values used in OpenFlow spec.
26 */ 26 */
27 -// TODO: Rename to a better name 27 +final class OpenFlowValueMapper {
28 -final class FlowModBuilderHelper {
29 28
30 // prohibit instantiation 29 // prohibit instantiation
31 - private FlowModBuilderHelper() {} 30 + private OpenFlowValueMapper() {}
32 31
33 private static final BiMap<GridType, Byte> GRID_TYPES = EnumHashBiMap.create(GridType.class); 32 private static final BiMap<GridType, Byte> GRID_TYPES = EnumHashBiMap.create(GridType.class);
34 static { 33 static {
...@@ -56,7 +55,7 @@ final class FlowModBuilderHelper { ...@@ -56,7 +55,7 @@ final class FlowModBuilderHelper {
56 } 55 }
57 56
58 /** 57 /**
59 - * Converts the specified input value to the corresponding value with the specified map. 58 + * Looks up the specified input value to the corresponding value with the specified map.
60 * 59 *
61 * @param map bidirectional mapping 60 * @param map bidirectional mapping
62 * @param input input value 61 * @param input input value
...@@ -64,83 +63,90 @@ final class FlowModBuilderHelper { ...@@ -64,83 +63,90 @@ final class FlowModBuilderHelper {
64 * @param <I> type of input value 63 * @param <I> type of input value
65 * @param <O> type of output value 64 * @param <O> type of output value
66 * @return the corresponding value stored in the specified map 65 * @return the corresponding value stored in the specified map
67 - * @throws UnsupportedConversionException if no corresponding value is found 66 + * @throws NoMappingFoundException if no corresponding value is found
68 */ 67 */
69 - private static <I, O> O convert(BiMap<I, O> map, I input, Class<O> cls) { 68 + private static <I, O> O lookup(BiMap<I, O> map, I input, Class<O> cls) {
70 if (!map.containsKey(input)) { 69 if (!map.containsKey(input)) {
71 - throw new UnsupportedConversionException(input, cls); 70 + throw new NoMappingFoundException(input, cls);
72 } 71 }
73 72
74 return map.get(input); 73 return map.get(input);
75 } 74 }
76 75
77 /** 76 /**
78 - * Converts a {@link GridType} to the corresponding byte value defined in 77 + * Looks up the corresponding byte value defined in
79 - * ONF "Optical Transport Protocol Extensions Version 1.0". 78 + * ONF "Optical Transport Protocol Extensions Version 1.0"
79 + * from the specified {@link GridType} instance.
80 * 80 *
81 * @param type grid type 81 * @param type grid type
82 * @return the byte value corresponding to the specified grid type 82 * @return the byte value corresponding to the specified grid type
83 - * @throws UnsupportedConversionException if the specified grid type is not supported 83 + * @throws NoMappingFoundException if the specified grid type is not found
84 */ 84 */
85 - static byte convertGridType(GridType type) { 85 + static byte lookupGridType(GridType type) {
86 - return convert(GRID_TYPES, type, Byte.class); 86 + return lookup(GRID_TYPES, type, Byte.class);
87 } 87 }
88 88
89 /** 89 /**
90 - * Converts a byte value for grid type 90 + * Looks up the corresponding {@link GridType} instance
91 - * defined in ONF "Optical Transport Protocol Extensions Version 1.0" 91 + * from the specified byte value for grid type
92 - * to the corresponding {@link GridType} instance. 92 + * defined in ONF "Optical Transport Protocol Extensions Version 1.0".
93 * 93 *
94 * @param type byte value as grid type defined the spec 94 * @param type byte value as grid type defined the spec
95 * @return the corresponding GridType instance 95 * @return the corresponding GridType instance
96 */ 96 */
97 - static GridType convertGridType(byte type) { 97 + static GridType lookupGridType(byte type) {
98 - return convert(GRID_TYPES.inverse(), type, GridType.class); 98 + return lookup(GRID_TYPES.inverse(), type, GridType.class);
99 } 99 }
100 100
101 /** 101 /**
102 - * Converts a {@link ChannelSpacing} to the corresponding byte value defined in 102 + * Looks up the corresponding byte value for channel spacing defined in
103 - * ONF "Optical Transport Protocol Extensions Version 1.0". 103 + * ONF "Optical Transport Protocol Extensions Version 1.0"
104 + * from the specified {@link ChannelSpacing} instance.
104 * 105 *
105 * @param spacing channel spacing 106 * @param spacing channel spacing
106 * @return byte value corresponding to the specified channel spacing 107 * @return byte value corresponding to the specified channel spacing
107 - * @throws UnsupportedConversionException if the specified channel spacing is not supported 108 + * @throws NoMappingFoundException if the specified channel spacing is not found
108 */ 109 */
109 - static byte convertChannelSpacing(ChannelSpacing spacing) { 110 + static byte lookupChannelSpacing(ChannelSpacing spacing) {
110 - return convert(CHANNEL_SPACING, spacing, Byte.class); 111 + return lookup(CHANNEL_SPACING, spacing, Byte.class);
111 } 112 }
112 113
113 /** 114 /**
114 - * Converts a byte value for channel spacing 115 + * Looks up the corresponding {@link ChannelSpacing} instance
115 - * defined in ONF "Optical Transport Protocol Extensions Version 1.0" 116 + * from the specified byte value for channel spacing
116 - * to the corresponding {@link ChannelSpacing} instance. 117 + * defined in ONF "Optical Transport Protocol Extensions Version 1.0".
117 * 118 *
118 * @param spacing byte value as channel spacing defined the spec 119 * @param spacing byte value as channel spacing defined the spec
119 * @return the corresponding ChannelSpacing instance 120 * @return the corresponding ChannelSpacing instance
121 + * @throws NoMappingFoundException if the specified channel spacing is not found
120 */ 122 */
121 - static ChannelSpacing convertChannelSpacing(byte spacing) { 123 + static ChannelSpacing lookupChannelSpacing(byte spacing) {
122 - return convert(CHANNEL_SPACING.inverse(), spacing, ChannelSpacing.class); 124 + return lookup(CHANNEL_SPACING.inverse(), spacing, ChannelSpacing.class);
123 } 125 }
124 126
125 /** 127 /**
126 - * Converts a {@link OchSignalType} to the corresponding byte value. 128 + * Looks up the corresponding byte value for Och signal type defined in
129 + * ONF "Optical Transport Protocol Extensions Version 1.0"
130 + * from the specified {@link OchSignalType} instance.
127 * 131 *
128 * @param signalType optical signal type 132 * @param signalType optical signal type
129 * @return byte value corresponding to the specified OCh signal type 133 * @return byte value corresponding to the specified OCh signal type
134 + * @throws NoMappingFoundException if the specified Och signal type is not found
130 */ 135 */
131 - static byte convertOchSignalType(OchSignalType signalType) { 136 + static byte lookupOchSignalType(OchSignalType signalType) {
132 - return convert(OCH_SIGNAL_TYPES, signalType, Byte.class); 137 + return lookup(OCH_SIGNAL_TYPES, signalType, Byte.class);
133 } 138 }
134 139
135 /** 140 /**
136 - * Converts a byte value for Och signal type 141 + * Looks up the the corresponding {@link OchSignalType} instance
137 - * defined in ONF "Optical Transport Protocol Extensions Version 1.0" 142 + * from the specified byte value for Och signal type defined in
138 - * to the corresponding {@link OchSignalType} instance. 143 + * ONF "Optical Transport Protocol Extensions Version 1.0".
139 * 144 *
140 * @param signalType byte value as Och singal type defined the spec 145 * @param signalType byte value as Och singal type defined the spec
141 * @return the corresponding OchSignalType instance 146 * @return the corresponding OchSignalType instance
147 + * @throws NoMappingFoundException if the specified Och signal type is not found
142 */ 148 */
143 - static OchSignalType convertOchSignalType(byte signalType) { 149 + static OchSignalType lookupOchSignalType(byte signalType) {
144 - return convert(OCH_SIGNAL_TYPES.inverse(), signalType, OchSignalType.class); 150 + return lookup(OCH_SIGNAL_TYPES.inverse(), signalType, OchSignalType.class);
145 } 151 }
146 } 152 }
......