Fixes [ONOS-5412] and implements [ONOS-5300]
Changes:
- Adds a new Interface for the selection algorithms;
- Re-implements FirstFit and Random selection;
- Adds a new option to select the algorithm;
- LabelAllocator provides a single interface;
- Fix MPLS encapsulation;
Change-Id: Ib07942355c45b7b9e7093fa85964c2ac20800b60
diff --git a/utils/misc/src/main/java/org/onlab/packet/MplsLabel.java b/utils/misc/src/main/java/org/onlab/packet/MplsLabel.java
index 82f951f..6a1418d 100644
--- a/utils/misc/src/main/java/org/onlab/packet/MplsLabel.java
+++ b/utils/misc/src/main/java/org/onlab/packet/MplsLabel.java
@@ -15,18 +15,18 @@
*/
package org.onlab.packet;
+import org.onlab.util.Identifier;
+
/**
* Representation of a MPLS label.
*/
-public class MplsLabel {
-
- private final int mplsLabel;
+public final class MplsLabel extends Identifier<Integer> {
// An MPLS Label maximum 20 bits.
public static final int MAX_MPLS = 0xFFFFF;
protected MplsLabel(int value) {
- this.mplsLabel = value;
+ super(value);
}
public static MplsLabel mplsLabel(int value) {
@@ -39,35 +39,27 @@
return new MplsLabel(value);
}
+ /**
+ * Creates a MplsLabel object using the supplied decimal string.
+ *
+ * @param value the MPLS identifier expressed as string
+ * @return Mplslabel object created from the string
+ */
+ public static MplsLabel mplsLabel(String value) {
+ try {
+ return MplsLabel.mplsLabel(Integer.parseInt(value));
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+
public int toInt() {
- return this.mplsLabel;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
-
- if (obj instanceof MplsLabel) {
-
- MplsLabel other = (MplsLabel) obj;
-
- if (this.mplsLabel == other.mplsLabel) {
- return true;
- }
- }
-
- return false;
- }
-
- @Override
- public int hashCode() {
- return this.mplsLabel;
+ return this.id();
}
@Override
public String toString() {
- return String.valueOf(this.mplsLabel);
+ return String.valueOf(this.identifier);
}
+
}