Jian Li
Committed by Ray Milkey

Remove ambiguity on instruction naming in InstructionCodec

In current implementation, the instruction that is defined in each
encodeLX hides the instruction that is defined out of methods.
This commit changes local instruction name to corresponding
instruction name to remove naming ambiguity.

Change-Id: I1f7f0766b66e903daa8ca3ebdea934366ec98308
...@@ -56,20 +56,19 @@ public final class EncodeInstructionCodecHelper { ...@@ -56,20 +56,19 @@ public final class EncodeInstructionCodecHelper {
56 * @param result json node that the instruction attributes are added to 56 * @param result json node that the instruction attributes are added to
57 */ 57 */
58 private void encodeL0(ObjectNode result) { 58 private void encodeL0(ObjectNode result) {
59 - L0ModificationInstruction instruction = 59 + L0ModificationInstruction l0Instruction = (L0ModificationInstruction) instruction;
60 - (L0ModificationInstruction) this.instruction; 60 + result.put(InstructionCodec.SUBTYPE, l0Instruction.subtype().name());
61 - result.put(InstructionCodec.SUBTYPE, instruction.subtype().name());
62 61
63 - switch (instruction.subtype()) { 62 + switch (l0Instruction.subtype()) {
64 case LAMBDA: 63 case LAMBDA:
65 final L0ModificationInstruction.ModLambdaInstruction modLambdaInstruction = 64 final L0ModificationInstruction.ModLambdaInstruction modLambdaInstruction =
66 - (L0ModificationInstruction.ModLambdaInstruction) instruction; 65 + (L0ModificationInstruction.ModLambdaInstruction) l0Instruction;
67 result.put(InstructionCodec.LAMBDA, modLambdaInstruction.lambda()); 66 result.put(InstructionCodec.LAMBDA, modLambdaInstruction.lambda());
68 break; 67 break;
69 68
70 case OCH: 69 case OCH:
71 L0ModificationInstruction.ModOchSignalInstruction ochSignalInstruction = 70 L0ModificationInstruction.ModOchSignalInstruction ochSignalInstruction =
72 - (L0ModificationInstruction.ModOchSignalInstruction) instruction; 71 + (L0ModificationInstruction.ModOchSignalInstruction) l0Instruction;
73 OchSignal ochSignal = ochSignalInstruction.lambda(); 72 OchSignal ochSignal = ochSignalInstruction.lambda();
74 result.put(InstructionCodec.GRID_TYPE, ochSignal.gridType().name()); 73 result.put(InstructionCodec.GRID_TYPE, ochSignal.gridType().name());
75 result.put(InstructionCodec.CHANNEL_SPACING, ochSignal.channelSpacing().name()); 74 result.put(InstructionCodec.CHANNEL_SPACING, ochSignal.channelSpacing().name());
...@@ -78,7 +77,7 @@ public final class EncodeInstructionCodecHelper { ...@@ -78,7 +77,7 @@ public final class EncodeInstructionCodecHelper {
78 break; 77 break;
79 78
80 default: 79 default:
81 - log.info("Cannot convert L0 subtype of {}", instruction.subtype()); 80 + log.info("Cannot convert L0 subtype of {}", l0Instruction.subtype());
82 } 81 }
83 } 82 }
84 83
...@@ -88,14 +87,13 @@ public final class EncodeInstructionCodecHelper { ...@@ -88,14 +87,13 @@ public final class EncodeInstructionCodecHelper {
88 * @param result json node that the instruction attributes are added to 87 * @param result json node that the instruction attributes are added to
89 */ 88 */
90 private void encodeL1(ObjectNode result) { 89 private void encodeL1(ObjectNode result) {
91 - L1ModificationInstruction instruction = 90 + L1ModificationInstruction l1Instruction = (L1ModificationInstruction) instruction;
92 - (L1ModificationInstruction) this.instruction; 91 + result.put(InstructionCodec.SUBTYPE, l1Instruction.subtype().name());
93 - result.put(InstructionCodec.SUBTYPE, instruction.subtype().name());
94 92
95 - switch (instruction.subtype()) { 93 + switch (l1Instruction.subtype()) {
96 case ODU_SIGID: 94 case ODU_SIGID:
97 final L1ModificationInstruction.ModOduSignalIdInstruction oduSignalIdInstruction = 95 final L1ModificationInstruction.ModOduSignalIdInstruction oduSignalIdInstruction =
98 - (L1ModificationInstruction.ModOduSignalIdInstruction) instruction; 96 + (L1ModificationInstruction.ModOduSignalIdInstruction) l1Instruction;
99 OduSignalId oduSignalId = oduSignalIdInstruction.oduSignalId(); 97 OduSignalId oduSignalId = oduSignalIdInstruction.oduSignalId();
100 98
101 ObjectNode child = result.putObject("oduSignalId"); 99 ObjectNode child = result.putObject("oduSignalId");
...@@ -106,7 +104,7 @@ public final class EncodeInstructionCodecHelper { ...@@ -106,7 +104,7 @@ public final class EncodeInstructionCodecHelper {
106 HexString.toHexString(oduSignalId.tributarySlotBitmap())); 104 HexString.toHexString(oduSignalId.tributarySlotBitmap()));
107 break; 105 break;
108 default: 106 default:
109 - log.info("Cannot convert L1 subtype of {}", instruction.subtype()); 107 + log.info("Cannot convert L1 subtype of {}", l1Instruction.subtype());
110 break; 108 break;
111 } 109 }
112 } 110 }
...@@ -117,39 +115,38 @@ public final class EncodeInstructionCodecHelper { ...@@ -117,39 +115,38 @@ public final class EncodeInstructionCodecHelper {
117 * @param result json node that the instruction attributes are added to 115 * @param result json node that the instruction attributes are added to
118 */ 116 */
119 private void encodeL2(ObjectNode result) { 117 private void encodeL2(ObjectNode result) {
120 - L2ModificationInstruction instruction = 118 + L2ModificationInstruction l2Instruction = (L2ModificationInstruction) instruction;
121 - (L2ModificationInstruction) this.instruction; 119 + result.put(InstructionCodec.SUBTYPE, l2Instruction.subtype().name());
122 - result.put(InstructionCodec.SUBTYPE, instruction.subtype().name());
123 120
124 - switch (instruction.subtype()) { 121 + switch (l2Instruction.subtype()) {
125 case ETH_SRC: 122 case ETH_SRC:
126 case ETH_DST: 123 case ETH_DST:
127 final L2ModificationInstruction.ModEtherInstruction modEtherInstruction = 124 final L2ModificationInstruction.ModEtherInstruction modEtherInstruction =
128 - (L2ModificationInstruction.ModEtherInstruction) instruction; 125 + (L2ModificationInstruction.ModEtherInstruction) l2Instruction;
129 result.put(InstructionCodec.MAC, modEtherInstruction.mac().toString()); 126 result.put(InstructionCodec.MAC, modEtherInstruction.mac().toString());
130 break; 127 break;
131 128
132 case VLAN_ID: 129 case VLAN_ID:
133 final L2ModificationInstruction.ModVlanIdInstruction modVlanIdInstruction = 130 final L2ModificationInstruction.ModVlanIdInstruction modVlanIdInstruction =
134 - (L2ModificationInstruction.ModVlanIdInstruction) instruction; 131 + (L2ModificationInstruction.ModVlanIdInstruction) l2Instruction;
135 result.put(InstructionCodec.VLAN_ID, modVlanIdInstruction.vlanId().toShort()); 132 result.put(InstructionCodec.VLAN_ID, modVlanIdInstruction.vlanId().toShort());
136 break; 133 break;
137 134
138 case VLAN_PCP: 135 case VLAN_PCP:
139 final L2ModificationInstruction.ModVlanPcpInstruction modVlanPcpInstruction = 136 final L2ModificationInstruction.ModVlanPcpInstruction modVlanPcpInstruction =
140 - (L2ModificationInstruction.ModVlanPcpInstruction) instruction; 137 + (L2ModificationInstruction.ModVlanPcpInstruction) l2Instruction;
141 result.put(InstructionCodec.VLAN_PCP, modVlanPcpInstruction.vlanPcp()); 138 result.put(InstructionCodec.VLAN_PCP, modVlanPcpInstruction.vlanPcp());
142 break; 139 break;
143 140
144 case MPLS_LABEL: 141 case MPLS_LABEL:
145 final L2ModificationInstruction.ModMplsLabelInstruction modMplsLabelInstruction = 142 final L2ModificationInstruction.ModMplsLabelInstruction modMplsLabelInstruction =
146 - (L2ModificationInstruction.ModMplsLabelInstruction) instruction; 143 + (L2ModificationInstruction.ModMplsLabelInstruction) l2Instruction;
147 result.put(InstructionCodec.MPLS_LABEL, modMplsLabelInstruction.label().toInt()); 144 result.put(InstructionCodec.MPLS_LABEL, modMplsLabelInstruction.label().toInt());
148 break; 145 break;
149 146
150 case MPLS_PUSH: 147 case MPLS_PUSH:
151 final L2ModificationInstruction.PushHeaderInstructions pushHeaderInstructions = 148 final L2ModificationInstruction.PushHeaderInstructions pushHeaderInstructions =
152 - (L2ModificationInstruction.PushHeaderInstructions) instruction; 149 + (L2ModificationInstruction.PushHeaderInstructions) l2Instruction;
153 150
154 result.put(InstructionCodec.ETHERNET_TYPE, 151 result.put(InstructionCodec.ETHERNET_TYPE,
155 pushHeaderInstructions.ethernetType().toShort()); 152 pushHeaderInstructions.ethernetType().toShort());
...@@ -157,12 +154,12 @@ public final class EncodeInstructionCodecHelper { ...@@ -157,12 +154,12 @@ public final class EncodeInstructionCodecHelper {
157 154
158 case TUNNEL_ID: 155 case TUNNEL_ID:
159 final L2ModificationInstruction.ModTunnelIdInstruction modTunnelIdInstruction = 156 final L2ModificationInstruction.ModTunnelIdInstruction modTunnelIdInstruction =
160 - (L2ModificationInstruction.ModTunnelIdInstruction) instruction; 157 + (L2ModificationInstruction.ModTunnelIdInstruction) l2Instruction;
161 result.put(InstructionCodec.TUNNEL_ID, modTunnelIdInstruction.tunnelId()); 158 result.put(InstructionCodec.TUNNEL_ID, modTunnelIdInstruction.tunnelId());
162 break; 159 break;
163 160
164 default: 161 default:
165 - log.info("Cannot convert L2 subtype of {}", instruction.subtype()); 162 + log.info("Cannot convert L2 subtype of {}", l2Instruction.subtype());
166 break; 163 break;
167 } 164 }
168 } 165 }
...@@ -173,28 +170,27 @@ public final class EncodeInstructionCodecHelper { ...@@ -173,28 +170,27 @@ public final class EncodeInstructionCodecHelper {
173 * @param result json node that the instruction attributes are added to 170 * @param result json node that the instruction attributes are added to
174 */ 171 */
175 private void encodeL3(ObjectNode result) { 172 private void encodeL3(ObjectNode result) {
176 - L3ModificationInstruction instruction = 173 + L3ModificationInstruction l3Instruction = (L3ModificationInstruction) instruction;
177 - (L3ModificationInstruction) this.instruction; 174 + result.put(InstructionCodec.SUBTYPE, l3Instruction.subtype().name());
178 - result.put(InstructionCodec.SUBTYPE, instruction.subtype().name()); 175 + switch (l3Instruction.subtype()) {
179 - switch (instruction.subtype()) {
180 case IPV4_SRC: 176 case IPV4_SRC:
181 case IPV4_DST: 177 case IPV4_DST:
182 case IPV6_SRC: 178 case IPV6_SRC:
183 case IPV6_DST: 179 case IPV6_DST:
184 final L3ModificationInstruction.ModIPInstruction modIPInstruction = 180 final L3ModificationInstruction.ModIPInstruction modIPInstruction =
185 - (L3ModificationInstruction.ModIPInstruction) instruction; 181 + (L3ModificationInstruction.ModIPInstruction) l3Instruction;
186 result.put(InstructionCodec.IP, modIPInstruction.ip().toString()); 182 result.put(InstructionCodec.IP, modIPInstruction.ip().toString());
187 break; 183 break;
188 184
189 case IPV6_FLABEL: 185 case IPV6_FLABEL:
190 final L3ModificationInstruction.ModIPv6FlowLabelInstruction 186 final L3ModificationInstruction.ModIPv6FlowLabelInstruction
191 modFlowLabelInstruction = 187 modFlowLabelInstruction =
192 - (L3ModificationInstruction.ModIPv6FlowLabelInstruction) instruction; 188 + (L3ModificationInstruction.ModIPv6FlowLabelInstruction) l3Instruction;
193 result.put(InstructionCodec.FLOW_LABEL, modFlowLabelInstruction.flowLabel()); 189 result.put(InstructionCodec.FLOW_LABEL, modFlowLabelInstruction.flowLabel());
194 break; 190 break;
195 191
196 default: 192 default:
197 - log.info("Cannot convert L3 subtype of {}", instruction.subtype()); 193 + log.info("Cannot convert L3 subtype of {}", l3Instruction.subtype());
198 break; 194 break;
199 } 195 }
200 } 196 }
...@@ -205,26 +201,25 @@ public final class EncodeInstructionCodecHelper { ...@@ -205,26 +201,25 @@ public final class EncodeInstructionCodecHelper {
205 * @param result json node that the instruction attributes are added to 201 * @param result json node that the instruction attributes are added to
206 */ 202 */
207 private void encodeL4(ObjectNode result) { 203 private void encodeL4(ObjectNode result) {
208 - L4ModificationInstruction instruction = 204 + L4ModificationInstruction l4Instruction = (L4ModificationInstruction) instruction;
209 - (L4ModificationInstruction) this.instruction; 205 + result.put(InstructionCodec.SUBTYPE, l4Instruction.subtype().name());
210 - result.put(InstructionCodec.SUBTYPE, instruction.subtype().name()); 206 + switch (l4Instruction.subtype()) {
211 - switch (instruction.subtype()) {
212 case TCP_DST: 207 case TCP_DST:
213 case TCP_SRC: 208 case TCP_SRC:
214 final L4ModificationInstruction.ModTransportPortInstruction modTcpPortInstruction = 209 final L4ModificationInstruction.ModTransportPortInstruction modTcpPortInstruction =
215 - (L4ModificationInstruction.ModTransportPortInstruction) instruction; 210 + (L4ModificationInstruction.ModTransportPortInstruction) l4Instruction;
216 result.put(InstructionCodec.TCP_PORT, modTcpPortInstruction.port().toInt()); 211 result.put(InstructionCodec.TCP_PORT, modTcpPortInstruction.port().toInt());
217 break; 212 break;
218 213
219 case UDP_DST: 214 case UDP_DST:
220 case UDP_SRC: 215 case UDP_SRC:
221 final L4ModificationInstruction.ModTransportPortInstruction modUdpPortInstruction = 216 final L4ModificationInstruction.ModTransportPortInstruction modUdpPortInstruction =
222 - (L4ModificationInstruction.ModTransportPortInstruction) instruction; 217 + (L4ModificationInstruction.ModTransportPortInstruction) l4Instruction;
223 result.put(InstructionCodec.UDP_PORT, modUdpPortInstruction.port().toInt()); 218 result.put(InstructionCodec.UDP_PORT, modUdpPortInstruction.port().toInt());
224 break; 219 break;
225 220
226 default: 221 default:
227 - log.info("Cannot convert L4 subtype of {}", instruction.subtype()); 222 + log.info("Cannot convert L4 subtype of {}", l4Instruction.subtype());
228 break; 223 break;
229 } 224 }
230 } 225 }
......