Yuta HIGUCHI

L2/L3 modification instruction bug fixes

- Fixed instanceOf with wrong type (ONOS-974)
- Aligned #toString() format to be the same as other instructions

Change-Id: I526c2ef8d92660e0b821a10f0cf87ee72a84cdf3
...@@ -304,13 +304,13 @@ public abstract class L2ModificationInstruction implements Instruction { ...@@ -304,13 +304,13 @@ public abstract class L2ModificationInstruction implements Instruction {
304 304
305 @Override 305 @Override
306 public String toString() { 306 public String toString() {
307 - return toStringHelper(type().toString()) 307 + return toStringHelper(subtype().toString())
308 .add("mpls", mplsLabel.intValue()).toString(); 308 .add("mpls", mplsLabel.intValue()).toString();
309 } 309 }
310 310
311 @Override 311 @Override
312 public int hashCode() { 312 public int hashCode() {
313 - return Objects.hash(mplsLabel); 313 + return Objects.hash(type(), subtype(), mplsLabel);
314 } 314 }
315 315
316 @Override 316 @Override
...@@ -330,7 +330,7 @@ public abstract class L2ModificationInstruction implements Instruction { ...@@ -330,7 +330,7 @@ public abstract class L2ModificationInstruction implements Instruction {
330 } 330 }
331 331
332 /** 332 /**
333 - * Represents a MPLS label modification. 333 + * Represents a MPLS TTL modification.
334 */ 334 */
335 public static final class ModMplsTtlInstruction extends 335 public static final class ModMplsTtlInstruction extends
336 L2ModificationInstruction { 336 L2ModificationInstruction {
...@@ -345,12 +345,13 @@ public abstract class L2ModificationInstruction implements Instruction { ...@@ -345,12 +345,13 @@ public abstract class L2ModificationInstruction implements Instruction {
345 345
346 @Override 346 @Override
347 public String toString() { 347 public String toString() {
348 - return type().toString(); 348 + return toStringHelper(subtype().toString())
349 + .toString();
349 } 350 }
350 351
351 @Override 352 @Override
352 public int hashCode() { 353 public int hashCode() {
353 - return Objects.hash(type(), L2SubType.DEC_MPLS_TTL); 354 + return Objects.hash(type(), subtype());
354 } 355 }
355 356
356 @Override 357 @Override
...@@ -358,9 +359,8 @@ public abstract class L2ModificationInstruction implements Instruction { ...@@ -358,9 +359,8 @@ public abstract class L2ModificationInstruction implements Instruction {
358 if (this == obj) { 359 if (this == obj) {
359 return true; 360 return true;
360 } 361 }
361 - if (obj instanceof ModMplsLabelInstruction) { 362 + if (obj instanceof ModMplsTtlInstruction) {
362 - ModMplsTtlInstruction that = (ModMplsTtlInstruction) obj; 363 + return true;
363 - return Objects.equals(this.type(), that.type());
364 } 364 }
365 return false; 365 return false;
366 } 366 }
......
...@@ -119,6 +119,9 @@ public abstract class L3ModificationInstruction implements Instruction { ...@@ -119,6 +119,9 @@ public abstract class L3ModificationInstruction implements Instruction {
119 } 119 }
120 } 120 }
121 121
122 + /**
123 + * Represents a L3 TTL modification instruction.
124 + */
122 public static final class ModTtlInstruction extends L3ModificationInstruction { 125 public static final class ModTtlInstruction extends L3ModificationInstruction {
123 126
124 private final L3SubType subtype; 127 private final L3SubType subtype;
...@@ -134,7 +137,8 @@ public abstract class L3ModificationInstruction implements Instruction { ...@@ -134,7 +137,8 @@ public abstract class L3ModificationInstruction implements Instruction {
134 137
135 @Override 138 @Override
136 public String toString() { 139 public String toString() {
137 - return subtype().toString(); 140 + return toStringHelper(subtype().toString())
141 + .toString();
138 } 142 }
139 143
140 @Override 144 @Override
...@@ -147,10 +151,10 @@ public abstract class L3ModificationInstruction implements Instruction { ...@@ -147,10 +151,10 @@ public abstract class L3ModificationInstruction implements Instruction {
147 if (this == obj) { 151 if (this == obj) {
148 return true; 152 return true;
149 } 153 }
150 - if (obj instanceof ModIPInstruction) { 154 + if (obj instanceof ModTtlInstruction) {
151 - ModIPInstruction that = (ModIPInstruction) obj; 155 + ModTtlInstruction that = (ModTtlInstruction) obj;
152 - return Objects.equals(this.type(), that.type()) && 156 + return Objects.equals(this.subtype(), that.subtype()) &&
153 - Objects.equals(this.subtype(), that.subtype()); 157 + Objects.equals(this.type(), that.type());
154 158
155 } 159 }
156 return false; 160 return false;
......