Move out element info from {Switch,Port,Link,Host}Impl
(ONOS-1719)
Change-Id: I8df50ce044173195474fd5c5168bab52f68907b3
diff --git a/src/main/java/net/onrc/onos/core/topology/HostImpl.java b/src/main/java/net/onrc/onos/core/topology/HostImpl.java
index 8ddca10..469d335 100644
--- a/src/main/java/net/onrc/onos/core/topology/HostImpl.java
+++ b/src/main/java/net/onrc/onos/core/topology/HostImpl.java
@@ -19,11 +19,6 @@
//////////////////////////////////////////////////////
private HostEvent deviceObj;
- ///////////////////
- /// In-memory index
- ///////////////////
-
- // none
/**
* Creates a Host object based on {@link HostEvent}.
diff --git a/src/main/java/net/onrc/onos/core/topology/LinkEvent.java b/src/main/java/net/onrc/onos/core/topology/LinkEvent.java
index 1618425..831b407 100644
--- a/src/main/java/net/onrc/onos/core/topology/LinkEvent.java
+++ b/src/main/java/net/onrc/onos/core/topology/LinkEvent.java
@@ -25,6 +25,8 @@
private final LinkTuple id;
// TODO add LastSeenTime, Capacity if appropriate
+ protected static final Double DEFAULT_CAPACITY = Double.POSITIVE_INFINITY;
+ private Double capacity = DEFAULT_CAPACITY;
/**
* Default constructor for Serializer to use.
@@ -62,8 +64,6 @@
*/
public LinkEvent(LinkEvent original) {
super(original);
- Validate.isTrue(Objects.equals(this.id, original.id));
-
this.id = original.id;
}
@@ -113,6 +113,30 @@
return getLinkTuple().getDst();
}
+ /**
+ * Gets the link capacity.
+ * TODO: What is the unit?
+ *
+ * @return capacity
+ */
+ public Double getCapacity() {
+ return capacity;
+ }
+
+ /**
+ * Sets the link capacity.
+ * TODO: What is the unit?
+ *
+ * @param capacity capacity
+ */
+ void setCapacity(Double capacity) {
+ if (isFrozen()) {
+ throw new IllegalStateException("Tried to modify frozen instance: " + this);
+ }
+
+ this.capacity = capacity;
+ }
+
@Override
public String toString() {
return "[LinkEvent " + getSrc() + "->" + getDst() + "]";
diff --git a/src/main/java/net/onrc/onos/core/topology/LinkImpl.java b/src/main/java/net/onrc/onos/core/topology/LinkImpl.java
index fce965a..5ad0194 100644
--- a/src/main/java/net/onrc/onos/core/topology/LinkImpl.java
+++ b/src/main/java/net/onrc/onos/core/topology/LinkImpl.java
@@ -20,15 +20,6 @@
//////////////////////////////////////////////////////
private LinkEvent linkObj;
- // TODO remove?
- protected static final Double DEFAULT_CAPACITY = Double.POSITIVE_INFINITY;
- protected Double capacity = DEFAULT_CAPACITY;
-
- ///////////////////
- /// In-memory index
- ///////////////////
-
- // none
/**
* Creates a Link object based on {@link LinkEvent}.
@@ -116,13 +107,20 @@
@Override
public Double getCapacity() {
- return capacity;
+ return this.linkObj.getCapacity();
}
void setCapacity(Double capacity) {
- this.capacity = capacity;
+ if (this.linkObj.isFrozen()) {
+ this.linkObj = new LinkEvent(this.linkObj);
+ this.linkObj.setCapacity(capacity);
+ this.linkObj.freeze();
+ } else {
+ this.linkObj.setCapacity(capacity);
+ }
}
+ // XXX actually replaces everything
void replaceStringAttributes(LinkEvent updated) {
Validate.isTrue(this.linkObj.getSrc().equals(updated.getSrc()),
"Wrong LinkEvent given.");
diff --git a/src/main/java/net/onrc/onos/core/topology/PortImpl.java b/src/main/java/net/onrc/onos/core/topology/PortImpl.java
index 099fa41..935b3c5 100644
--- a/src/main/java/net/onrc/onos/core/topology/PortImpl.java
+++ b/src/main/java/net/onrc/onos/core/topology/PortImpl.java
@@ -23,10 +23,6 @@
//////////////////////////////////////////////////////
private PortEvent portObj;
- ///////////////////
- /// In-memory index
- ///////////////////
-
/**
* Creates a Port object based on {@link PortEvent}.
diff --git a/src/main/java/net/onrc/onos/core/topology/SwitchImpl.java b/src/main/java/net/onrc/onos/core/topology/SwitchImpl.java
index aa730c3..b0486b0 100644
--- a/src/main/java/net/onrc/onos/core/topology/SwitchImpl.java
+++ b/src/main/java/net/onrc/onos/core/topology/SwitchImpl.java
@@ -27,11 +27,6 @@
//////////////////////////////////////////////////////
private SwitchEvent switchObj;
- ///////////////////
- /// In-memory index
- ///////////////////
-
- // none
/**
* Creates a Switch object with empty attributes.