Committed by
Jonathan Hart
Instruction related fixes
- Removed redundant equality check. (ONOS-975) - Enforced using Instruction Factory methods. - cosmetic fixes. Change-Id: I178b55f8568c1a9132f0aa88465b8b34dc2b2df2
Showing
5 changed files
with
35 additions
and
59 deletions
| ... | @@ -260,11 +260,13 @@ public final class Instructions { | ... | @@ -260,11 +260,13 @@ public final class Instructions { |
| 260 | return new TableTypeTransition(type); | 260 | return new TableTypeTransition(type); |
| 261 | } | 261 | } |
| 262 | 262 | ||
| 263 | - /* | 263 | + /** |
| 264 | - * Drop instructions | 264 | + * Drop instruction. |
| 265 | */ | 265 | */ |
| 266 | - | ||
| 267 | public static final class DropInstruction implements Instruction { | 266 | public static final class DropInstruction implements Instruction { |
| 267 | + | ||
| 268 | + private DropInstruction() {} | ||
| 269 | + | ||
| 268 | @Override | 270 | @Override |
| 269 | public Type type() { | 271 | public Type type() { |
| 270 | return Type.DROP; | 272 | return Type.DROP; |
| ... | @@ -287,18 +289,15 @@ public final class Instructions { | ... | @@ -287,18 +289,15 @@ public final class Instructions { |
| 287 | return true; | 289 | return true; |
| 288 | } | 290 | } |
| 289 | if (obj instanceof DropInstruction) { | 291 | if (obj instanceof DropInstruction) { |
| 290 | - DropInstruction that = (DropInstruction) obj; | 292 | + return true; |
| 291 | - return Objects.equals(type(), that.type()); | ||
| 292 | - | ||
| 293 | } | 293 | } |
| 294 | return false; | 294 | return false; |
| 295 | } | 295 | } |
| 296 | } | 296 | } |
| 297 | 297 | ||
| 298 | - /* | 298 | + /** |
| 299 | - * Output Instruction | 299 | + * Output Instruction. |
| 300 | */ | 300 | */ |
| 301 | - | ||
| 302 | public static final class OutputInstruction implements Instruction { | 301 | public static final class OutputInstruction implements Instruction { |
| 303 | private final PortNumber port; | 302 | private final PortNumber port; |
| 304 | 303 | ||
| ... | @@ -339,10 +338,9 @@ public final class Instructions { | ... | @@ -339,10 +338,9 @@ public final class Instructions { |
| 339 | } | 338 | } |
| 340 | } | 339 | } |
| 341 | 340 | ||
| 342 | - /* | 341 | + /** |
| 343 | - * Group Instruction | 342 | + * Group Instruction. |
| 344 | */ | 343 | */ |
| 345 | - | ||
| 346 | public static final class GroupInstruction implements Instruction { | 344 | public static final class GroupInstruction implements Instruction { |
| 347 | private final GroupId groupId; | 345 | private final GroupId groupId; |
| 348 | 346 | ||
| ... | @@ -389,7 +387,7 @@ public final class Instructions { | ... | @@ -389,7 +387,7 @@ public final class Instructions { |
| 389 | public static class TableTypeTransition implements Instruction { | 387 | public static class TableTypeTransition implements Instruction { |
| 390 | private final FlowRule.Type tableType; | 388 | private final FlowRule.Type tableType; |
| 391 | 389 | ||
| 392 | - public TableTypeTransition(FlowRule.Type type) { | 390 | + TableTypeTransition(FlowRule.Type type) { |
| 393 | this.tableType = type; | 391 | this.tableType = type; |
| 394 | } | 392 | } |
| 395 | 393 | ||
| ... | @@ -405,7 +403,7 @@ public final class Instructions { | ... | @@ -405,7 +403,7 @@ public final class Instructions { |
| 405 | @Override | 403 | @Override |
| 406 | public String toString() { | 404 | public String toString() { |
| 407 | return toStringHelper(type().toString()) | 405 | return toStringHelper(type().toString()) |
| 408 | - .add("group ID", this.tableType).toString(); | 406 | + .add("tableType", this.tableType).toString(); |
| 409 | } | 407 | } |
| 410 | 408 | ||
| 411 | @Override | 409 | @Override | ... | ... |
| ... | @@ -36,7 +36,7 @@ public abstract class L0ModificationInstruction implements Instruction { | ... | @@ -36,7 +36,7 @@ public abstract class L0ModificationInstruction implements Instruction { |
| 36 | public abstract L0SubType subtype(); | 36 | public abstract L0SubType subtype(); |
| 37 | 37 | ||
| 38 | @Override | 38 | @Override |
| 39 | - public Type type() { | 39 | + public final Type type() { |
| 40 | return Type.L0MODIFICATION; | 40 | return Type.L0MODIFICATION; |
| 41 | } | 41 | } |
| 42 | 42 | ||
| ... | @@ -48,7 +48,7 @@ public abstract class L0ModificationInstruction implements Instruction { | ... | @@ -48,7 +48,7 @@ public abstract class L0ModificationInstruction implements Instruction { |
| 48 | private final L0SubType subtype; | 48 | private final L0SubType subtype; |
| 49 | private final short lambda; | 49 | private final short lambda; |
| 50 | 50 | ||
| 51 | - public ModLambdaInstruction(L0SubType subType, short lambda) { | 51 | + ModLambdaInstruction(L0SubType subType, short lambda) { |
| 52 | this.subtype = subType; | 52 | this.subtype = subType; |
| 53 | this.lambda = lambda; | 53 | this.lambda = lambda; |
| 54 | } | 54 | } |
| ... | @@ -81,7 +81,6 @@ public abstract class L0ModificationInstruction implements Instruction { | ... | @@ -81,7 +81,6 @@ public abstract class L0ModificationInstruction implements Instruction { |
| 81 | if (obj instanceof ModLambdaInstruction) { | 81 | if (obj instanceof ModLambdaInstruction) { |
| 82 | ModLambdaInstruction that = (ModLambdaInstruction) obj; | 82 | ModLambdaInstruction that = (ModLambdaInstruction) obj; |
| 83 | return Objects.equals(lambda, that.lambda) && | 83 | return Objects.equals(lambda, that.lambda) && |
| 84 | - Objects.equals(this.type(), that.type()) && | ||
| 85 | Objects.equals(subtype, that.subtype); | 84 | Objects.equals(subtype, that.subtype); |
| 86 | } | 85 | } |
| 87 | return false; | 86 | return false; | ... | ... |
| ... | @@ -80,7 +80,7 @@ public abstract class L2ModificationInstruction implements Instruction { | ... | @@ -80,7 +80,7 @@ public abstract class L2ModificationInstruction implements Instruction { |
| 80 | public abstract L2SubType subtype(); | 80 | public abstract L2SubType subtype(); |
| 81 | 81 | ||
| 82 | @Override | 82 | @Override |
| 83 | - public Type type() { | 83 | + public final Type type() { |
| 84 | return Type.L2MODIFICATION; | 84 | return Type.L2MODIFICATION; |
| 85 | } | 85 | } |
| 86 | 86 | ||
| ... | @@ -92,7 +92,7 @@ public abstract class L2ModificationInstruction implements Instruction { | ... | @@ -92,7 +92,7 @@ public abstract class L2ModificationInstruction implements Instruction { |
| 92 | private final L2SubType subtype; | 92 | private final L2SubType subtype; |
| 93 | private final MacAddress mac; | 93 | private final MacAddress mac; |
| 94 | 94 | ||
| 95 | - public ModEtherInstruction(L2SubType subType, MacAddress addr) { | 95 | + ModEtherInstruction(L2SubType subType, MacAddress addr) { |
| 96 | 96 | ||
| 97 | this.subtype = subType; | 97 | this.subtype = subType; |
| 98 | this.mac = addr; | 98 | this.mac = addr; |
| ... | @@ -126,16 +126,13 @@ public abstract class L2ModificationInstruction implements Instruction { | ... | @@ -126,16 +126,13 @@ public abstract class L2ModificationInstruction implements Instruction { |
| 126 | if (obj instanceof ModEtherInstruction) { | 126 | if (obj instanceof ModEtherInstruction) { |
| 127 | ModEtherInstruction that = (ModEtherInstruction) obj; | 127 | ModEtherInstruction that = (ModEtherInstruction) obj; |
| 128 | return Objects.equals(mac, that.mac) && | 128 | return Objects.equals(mac, that.mac) && |
| 129 | - Objects.equals(this.type(), that.type()) && | ||
| 130 | Objects.equals(subtype, that.subtype); | 129 | Objects.equals(subtype, that.subtype); |
| 131 | - | ||
| 132 | } | 130 | } |
| 133 | return false; | 131 | return false; |
| 134 | } | 132 | } |
| 135 | - | ||
| 136 | - | ||
| 137 | } | 133 | } |
| 138 | 134 | ||
| 135 | + // TODO This instruction is reused for Pop-Mpls. Consider renaming. | ||
| 139 | public static final class PushHeaderInstructions extends | 136 | public static final class PushHeaderInstructions extends |
| 140 | L2ModificationInstruction { | 137 | L2ModificationInstruction { |
| 141 | 138 | ||
| ... | @@ -191,7 +188,7 @@ public abstract class L2ModificationInstruction implements Instruction { | ... | @@ -191,7 +188,7 @@ public abstract class L2ModificationInstruction implements Instruction { |
| 191 | 188 | ||
| 192 | private final VlanId vlanId; | 189 | private final VlanId vlanId; |
| 193 | 190 | ||
| 194 | - public ModVlanIdInstruction(VlanId vlanId) { | 191 | + ModVlanIdInstruction(VlanId vlanId) { |
| 195 | this.vlanId = vlanId; | 192 | this.vlanId = vlanId; |
| 196 | } | 193 | } |
| 197 | 194 | ||
| ... | @@ -222,15 +219,10 @@ public abstract class L2ModificationInstruction implements Instruction { | ... | @@ -222,15 +219,10 @@ public abstract class L2ModificationInstruction implements Instruction { |
| 222 | } | 219 | } |
| 223 | if (obj instanceof ModVlanIdInstruction) { | 220 | if (obj instanceof ModVlanIdInstruction) { |
| 224 | ModVlanIdInstruction that = (ModVlanIdInstruction) obj; | 221 | ModVlanIdInstruction that = (ModVlanIdInstruction) obj; |
| 225 | - return Objects.equals(vlanId, that.vlanId) && | 222 | + return Objects.equals(vlanId, that.vlanId); |
| 226 | - Objects.equals(this.type(), that.type()) && | ||
| 227 | - Objects.equals(this.subtype(), that.subtype()); | ||
| 228 | - | ||
| 229 | } | 223 | } |
| 230 | return false; | 224 | return false; |
| 231 | } | 225 | } |
| 232 | - | ||
| 233 | - | ||
| 234 | } | 226 | } |
| 235 | 227 | ||
| 236 | /** | 228 | /** |
| ... | @@ -240,7 +232,7 @@ public abstract class L2ModificationInstruction implements Instruction { | ... | @@ -240,7 +232,7 @@ public abstract class L2ModificationInstruction implements Instruction { |
| 240 | 232 | ||
| 241 | private final Byte vlanPcp; | 233 | private final Byte vlanPcp; |
| 242 | 234 | ||
| 243 | - public ModVlanPcpInstruction(Byte vlanPcp) { | 235 | + ModVlanPcpInstruction(Byte vlanPcp) { |
| 244 | this.vlanPcp = vlanPcp; | 236 | this.vlanPcp = vlanPcp; |
| 245 | } | 237 | } |
| 246 | 238 | ||
| ... | @@ -271,26 +263,22 @@ public abstract class L2ModificationInstruction implements Instruction { | ... | @@ -271,26 +263,22 @@ public abstract class L2ModificationInstruction implements Instruction { |
| 271 | } | 263 | } |
| 272 | if (obj instanceof ModVlanPcpInstruction) { | 264 | if (obj instanceof ModVlanPcpInstruction) { |
| 273 | ModVlanPcpInstruction that = (ModVlanPcpInstruction) obj; | 265 | ModVlanPcpInstruction that = (ModVlanPcpInstruction) obj; |
| 274 | - return Objects.equals(vlanPcp, that.vlanPcp) && | 266 | + return Objects.equals(vlanPcp, that.vlanPcp); |
| 275 | - Objects.equals(this.type(), that.type()) && | ||
| 276 | - Objects.equals(this.subtype(), that.subtype()); | ||
| 277 | - | ||
| 278 | } | 267 | } |
| 279 | return false; | 268 | return false; |
| 280 | } | 269 | } |
| 281 | - | ||
| 282 | } | 270 | } |
| 283 | 271 | ||
| 284 | 272 | ||
| 285 | /** | 273 | /** |
| 286 | * Represents a MPLS label modification. | 274 | * Represents a MPLS label modification. |
| 287 | */ | 275 | */ |
| 288 | - public static final class ModMplsLabelInstruction extends | 276 | + public static final class ModMplsLabelInstruction |
| 289 | - L2ModificationInstruction { | 277 | + extends L2ModificationInstruction { |
| 290 | 278 | ||
| 291 | private final MplsLabel mplsLabel; | 279 | private final MplsLabel mplsLabel; |
| 292 | 280 | ||
| 293 | - public ModMplsLabelInstruction(MplsLabel mplsLabel) { | 281 | + ModMplsLabelInstruction(MplsLabel mplsLabel) { |
| 294 | this.mplsLabel = mplsLabel; | 282 | this.mplsLabel = mplsLabel; |
| 295 | } | 283 | } |
| 296 | 284 | ||
| ... | @@ -321,10 +309,7 @@ public abstract class L2ModificationInstruction implements Instruction { | ... | @@ -321,10 +309,7 @@ public abstract class L2ModificationInstruction implements Instruction { |
| 321 | } | 309 | } |
| 322 | if (obj instanceof ModMplsLabelInstruction) { | 310 | if (obj instanceof ModMplsLabelInstruction) { |
| 323 | ModMplsLabelInstruction that = (ModMplsLabelInstruction) obj; | 311 | ModMplsLabelInstruction that = (ModMplsLabelInstruction) obj; |
| 324 | - return Objects.equals(mplsLabel, that.mplsLabel) && | 312 | + return Objects.equals(mplsLabel, that.mplsLabel); |
| 325 | - Objects.equals(this.type(), that.type()); | ||
| 326 | - | ||
| 327 | - | ||
| 328 | } | 313 | } |
| 329 | return false; | 314 | return false; |
| 330 | } | 315 | } |
| ... | @@ -333,10 +318,10 @@ public abstract class L2ModificationInstruction implements Instruction { | ... | @@ -333,10 +318,10 @@ public abstract class L2ModificationInstruction implements Instruction { |
| 333 | /** | 318 | /** |
| 334 | * Represents a MPLS TTL modification. | 319 | * Represents a MPLS TTL modification. |
| 335 | */ | 320 | */ |
| 336 | - public static final class ModMplsTtlInstruction extends | 321 | + public static final class ModMplsTtlInstruction |
| 337 | - L2ModificationInstruction { | 322 | + extends L2ModificationInstruction { |
| 338 | 323 | ||
| 339 | - public ModMplsTtlInstruction() { | 324 | + ModMplsTtlInstruction() { |
| 340 | } | 325 | } |
| 341 | 326 | ||
| 342 | @Override | 327 | @Override | ... | ... |
| ... | @@ -80,7 +80,7 @@ public abstract class L3ModificationInstruction implements Instruction { | ... | @@ -80,7 +80,7 @@ public abstract class L3ModificationInstruction implements Instruction { |
| 80 | public abstract L3SubType subtype(); | 80 | public abstract L3SubType subtype(); |
| 81 | 81 | ||
| 82 | @Override | 82 | @Override |
| 83 | - public Type type() { | 83 | + public final Type type() { |
| 84 | return Type.L3MODIFICATION; | 84 | return Type.L3MODIFICATION; |
| 85 | } | 85 | } |
| 86 | 86 | ||
| ... | @@ -92,7 +92,7 @@ public abstract class L3ModificationInstruction implements Instruction { | ... | @@ -92,7 +92,7 @@ public abstract class L3ModificationInstruction implements Instruction { |
| 92 | private final L3SubType subtype; | 92 | private final L3SubType subtype; |
| 93 | private final IpAddress ip; | 93 | private final IpAddress ip; |
| 94 | 94 | ||
| 95 | - public ModIPInstruction(L3SubType subType, IpAddress addr) { | 95 | + ModIPInstruction(L3SubType subType, IpAddress addr) { |
| 96 | 96 | ||
| 97 | this.subtype = subType; | 97 | this.subtype = subType; |
| 98 | this.ip = addr; | 98 | this.ip = addr; |
| ... | @@ -126,9 +126,7 @@ public abstract class L3ModificationInstruction implements Instruction { | ... | @@ -126,9 +126,7 @@ public abstract class L3ModificationInstruction implements Instruction { |
| 126 | if (obj instanceof ModIPInstruction) { | 126 | if (obj instanceof ModIPInstruction) { |
| 127 | ModIPInstruction that = (ModIPInstruction) obj; | 127 | ModIPInstruction that = (ModIPInstruction) obj; |
| 128 | return Objects.equals(ip, that.ip) && | 128 | return Objects.equals(ip, that.ip) && |
| 129 | - Objects.equals(this.type(), that.type()) && | ||
| 130 | Objects.equals(this.subtype(), that.subtype()); | 129 | Objects.equals(this.subtype(), that.subtype()); |
| 131 | - | ||
| 132 | } | 130 | } |
| 133 | return false; | 131 | return false; |
| 134 | } | 132 | } |
| ... | @@ -148,7 +146,7 @@ public abstract class L3ModificationInstruction implements Instruction { | ... | @@ -148,7 +146,7 @@ public abstract class L3ModificationInstruction implements Instruction { |
| 148 | * | 146 | * |
| 149 | * @param flowLabel the IPv6 flow label to set in the treatment (20 bits) | 147 | * @param flowLabel the IPv6 flow label to set in the treatment (20 bits) |
| 150 | */ | 148 | */ |
| 151 | - public ModIPv6FlowLabelInstruction(int flowLabel) { | 149 | + ModIPv6FlowLabelInstruction(int flowLabel) { |
| 152 | this.flowLabel = flowLabel & MASK; | 150 | this.flowLabel = flowLabel & MASK; |
| 153 | } | 151 | } |
| 154 | 152 | ||
| ... | @@ -185,9 +183,7 @@ public abstract class L3ModificationInstruction implements Instruction { | ... | @@ -185,9 +183,7 @@ public abstract class L3ModificationInstruction implements Instruction { |
| 185 | if (obj instanceof ModIPv6FlowLabelInstruction) { | 183 | if (obj instanceof ModIPv6FlowLabelInstruction) { |
| 186 | ModIPv6FlowLabelInstruction that = | 184 | ModIPv6FlowLabelInstruction that = |
| 187 | (ModIPv6FlowLabelInstruction) obj; | 185 | (ModIPv6FlowLabelInstruction) obj; |
| 188 | - return Objects.equals(flowLabel, that.flowLabel) && | 186 | + return Objects.equals(flowLabel, that.flowLabel); |
| 189 | - Objects.equals(this.type(), that.type()) && | ||
| 190 | - Objects.equals(this.subtype(), that.subtype()); | ||
| 191 | } | 187 | } |
| 192 | return false; | 188 | return false; |
| 193 | } | 189 | } |
| ... | @@ -200,7 +196,7 @@ public abstract class L3ModificationInstruction implements Instruction { | ... | @@ -200,7 +196,7 @@ public abstract class L3ModificationInstruction implements Instruction { |
| 200 | 196 | ||
| 201 | private final L3SubType subtype; | 197 | private final L3SubType subtype; |
| 202 | 198 | ||
| 203 | - public ModTtlInstruction(L3SubType subtype) { | 199 | + ModTtlInstruction(L3SubType subtype) { |
| 204 | this.subtype = subtype; | 200 | this.subtype = subtype; |
| 205 | } | 201 | } |
| 206 | 202 | ||
| ... | @@ -227,9 +223,7 @@ public abstract class L3ModificationInstruction implements Instruction { | ... | @@ -227,9 +223,7 @@ public abstract class L3ModificationInstruction implements Instruction { |
| 227 | } | 223 | } |
| 228 | if (obj instanceof ModTtlInstruction) { | 224 | if (obj instanceof ModTtlInstruction) { |
| 229 | ModTtlInstruction that = (ModTtlInstruction) obj; | 225 | ModTtlInstruction that = (ModTtlInstruction) obj; |
| 230 | - return Objects.equals(this.subtype(), that.subtype()) && | 226 | + return Objects.equals(this.subtype(), that.subtype()); |
| 231 | - Objects.equals(this.type(), that.type()); | ||
| 232 | - | ||
| 233 | } | 227 | } |
| 234 | return false; | 228 | return false; |
| 235 | } | 229 | } | ... | ... |
| ... | @@ -73,7 +73,7 @@ public class InstructionCodecTest { | ... | @@ -73,7 +73,7 @@ public class InstructionCodecTest { |
| 73 | @Test | 73 | @Test |
| 74 | public void dropInstructionTest() { | 74 | public void dropInstructionTest() { |
| 75 | final Instructions.DropInstruction instruction = | 75 | final Instructions.DropInstruction instruction = |
| 76 | - new Instructions.DropInstruction(); | 76 | + Instructions.createDrop(); |
| 77 | final ObjectNode instructionJson = | 77 | final ObjectNode instructionJson = |
| 78 | instructionCodec.encode(instruction, context); | 78 | instructionCodec.encode(instruction, context); |
| 79 | assertThat(instructionJson, matchesInstruction(instruction)); | 79 | assertThat(instructionJson, matchesInstruction(instruction)); | ... | ... |
-
Please register or login to post a comment