Use LinkEvent class instead of Link class for elements of Path
Change-Id: Iaf40f6e21d7cc411476909d3a3f32746787e16a6
diff --git a/src/main/java/net/onrc/onos/intent/ConstrainedBFSTree.java b/src/main/java/net/onrc/onos/intent/ConstrainedBFSTree.java
index 30bdb01..a219d97 100644
--- a/src/main/java/net/onrc/onos/intent/ConstrainedBFSTree.java
+++ b/src/main/java/net/onrc/onos/intent/ConstrainedBFSTree.java
@@ -5,6 +5,7 @@
import java.util.LinkedList;
import net.onrc.onos.ofcontroller.networkgraph.Link;
+import net.onrc.onos.ofcontroller.networkgraph.LinkEvent;
import net.onrc.onos.ofcontroller.networkgraph.Path;
import net.onrc.onos.ofcontroller.networkgraph.Switch;
@@ -17,10 +18,10 @@
* @author Toshio Koide (t-koide@onlab.us)
*/
public class ConstrainedBFSTree {
- LinkedList<Switch> switchQueue = new LinkedList<Switch>();
- HashSet<Switch> switchSearched = new HashSet<Switch>();
- HashMap<Switch, Link> upstreamLinks = new HashMap<Switch, Link>();
- HashMap<Switch, Path> paths = new HashMap<Switch, Path>();
+ LinkedList<Switch> switchQueue = new LinkedList<>();
+ HashSet<Switch> switchSearched = new HashSet<>();
+ HashMap<Long, LinkEvent> upstreamLinks = new HashMap<>();
+ HashMap<Switch, Path> paths = new HashMap<>();
Switch rootSwitch;
PathIntentMap intents = null;
double bandwidth = 0.0; // 0.0 means no limit for bandwidth (normal BFS tree)
@@ -48,20 +49,21 @@
if (intents != null && intents.getAvailableBandwidth(link) < bandwidth) continue;
switchQueue.add(reachedSwitch);
switchSearched.add(reachedSwitch);
- upstreamLinks.put(reachedSwitch, link);
+ upstreamLinks.put(reachedSwitch.getDpid(), new LinkEvent(link));
}
}
}
public Path getPath(Switch leafSwitch) {
Path path = paths.get(leafSwitch);
+ Long rootSwitchDpid = rootSwitch.getDpid();
if (path == null && switchSearched.contains(leafSwitch)) {
path = new Path();
- Switch sw = leafSwitch;
- while (sw != rootSwitch) {
- Link upstreamLink = upstreamLinks.get(sw);
+ Long sw = leafSwitch.getDpid();
+ while (sw != rootSwitchDpid) {
+ LinkEvent upstreamLink = upstreamLinks.get(sw);
path.add(0, upstreamLink);
- sw = upstreamLink.getSourcePort().getSwitch();
+ sw = upstreamLink.getSrc().getDpid();
}
paths.put(leafSwitch, path);
}
diff --git a/src/main/java/net/onrc/onos/intent/Intent.java b/src/main/java/net/onrc/onos/intent/Intent.java
index 002d6f6..20088bd 100644
--- a/src/main/java/net/onrc/onos/intent/Intent.java
+++ b/src/main/java/net/onrc/onos/intent/Intent.java
@@ -3,7 +3,7 @@
/**
* @author Toshio Koide (t-koide@onlab.us)
*/
-public class Intent {
+public class Intent {
public enum IntentState {
CREATED,
INST_REQ,
@@ -50,7 +50,7 @@
public int hashCode() {
return id.hashCode();
}
-
+
@Override
public String toString() {
return id.toString() + ", " + state.toString();
diff --git a/src/main/java/net/onrc/onos/intent/IntentDeserializer.java b/src/main/java/net/onrc/onos/intent/IntentDeserializer.java
deleted file mode 100644
index a3a6ae6..0000000
--- a/src/main/java/net/onrc/onos/intent/IntentDeserializer.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package net.onrc.onos.intent;
-
-
-/**
- * @author Toshio Koide (t-koide@onlab.us)
- */
-public class IntentDeserializer {
- private String id;
- private String className;
- private Intent intent = null;
-
- public IntentDeserializer(byte[] b) {
- // TODO deserialize object and get (unique id, class name, object data) tuple.
- id = "id";
- className = "pi";
- byte[] objectData = null;
-
- switch (className) {
- case "pi":
- parsePathIntent(objectData);
- break;
- case "spi":
- parseShortestPathIntent(objectData);
- break;
- case "cspi":
- parseConstrainedShortestPathIntent(objectData);
- break;
- default:
- // TODO error
- }
- }
-
- private void parsePathIntent(byte[] objectData) {
- // TODO deserialize object and create instance
- intent = new PathIntent(id, null, 0, null);
- }
-
- private void parseShortestPathIntent(byte[] objectData) {
- // TODO deserialize object and create instance
- intent = new ShortestPathIntent(id, 0L, 0L, 0L, 0L, 0L, 0L);
- }
-
- private void parseConstrainedShortestPathIntent(byte[] objectData) {
- // TODO deserialize object and create instance
- intent = new ConstrainedShortestPathIntent(id, 0L, 0L, 0L, 0L, 0L, 0L, 0.0);
- }
-
- public Intent getIntent() {
- return intent;
- }
-}
diff --git a/src/main/java/net/onrc/onos/intent/IntentMap.java b/src/main/java/net/onrc/onos/intent/IntentMap.java
index 9969433..4657706 100644
--- a/src/main/java/net/onrc/onos/intent/IntentMap.java
+++ b/src/main/java/net/onrc/onos/intent/IntentMap.java
@@ -4,7 +4,6 @@
import java.util.EventListener;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map.Entry;
@@ -50,17 +49,17 @@
private HashSet<ChangedListener> listeners = new HashSet<>();
private HashMap<String, Intent> intents = new HashMap<>();
-
+
protected void putIntent(Intent intent) {
if (intents.containsKey(intent.getId()))
removeIntent(intent.getId());
intents.put(intent.getId(), intent);
}
-
+
protected void removeIntent(String intentId) {
intents.remove(intentId);
}
-
+
public Intent getIntent(String intentId) {
return intents.get(intentId);
}
diff --git a/src/main/java/net/onrc/onos/intent/IntentOperation.java b/src/main/java/net/onrc/onos/intent/IntentOperation.java
index c769811..506dd52 100644
--- a/src/main/java/net/onrc/onos/intent/IntentOperation.java
+++ b/src/main/java/net/onrc/onos/intent/IntentOperation.java
@@ -26,7 +26,7 @@
public Operator operator;
public Intent intent;
-
+
@Override
public String toString() {
return operator.toString() + ", (" + intent.toString() + ")";
diff --git a/src/main/java/net/onrc/onos/intent/IntentOperationList.java b/src/main/java/net/onrc/onos/intent/IntentOperationList.java
index af00373..05e5b5c 100644
--- a/src/main/java/net/onrc/onos/intent/IntentOperationList.java
+++ b/src/main/java/net/onrc/onos/intent/IntentOperationList.java
@@ -2,9 +2,12 @@
import java.util.ArrayList;
+/**
+ * @author Toshio Koide (t-koide@onlab.us)
+ */
public class IntentOperationList extends ArrayList<IntentOperation> {
private static final long serialVersionUID = -3894081461861052610L;
-
+
public boolean add(IntentOperation.Operator op, Intent intent) {
return add(new IntentOperation(op, intent));
}
diff --git a/src/main/java/net/onrc/onos/intent/PathIntent.java b/src/main/java/net/onrc/onos/intent/PathIntent.java
index a5454fa..e000828 100644
--- a/src/main/java/net/onrc/onos/intent/PathIntent.java
+++ b/src/main/java/net/onrc/onos/intent/PathIntent.java
@@ -1,19 +1,12 @@
package net.onrc.onos.intent;
-import java.util.LinkedList;
-import java.util.List;
-
-import net.onrc.onos.ofcontroller.networkgraph.Link;
-import net.onrc.onos.ofcontroller.networkgraph.LinkEvent;
-import net.onrc.onos.ofcontroller.networkgraph.NetworkGraph;
import net.onrc.onos.ofcontroller.networkgraph.Path;
-import net.onrc.onos.ofcontroller.networkgraph.Port;
/**
* @author Toshio Koide (t-koide@onlab.us)
*/
public class PathIntent extends Intent {
- protected List<LinkEvent> path;
+ protected Path path;
protected double bandwidth;
protected Intent parentIntent;
@@ -24,7 +17,7 @@
}
/**
- *
+ *
* @param graph
* @param path
* @param bandwidth bandwidth which should be allocated for the path.
@@ -34,14 +27,7 @@
*/
public PathIntent(String id, Path path, double bandwidth, Intent parentIntent) {
super(id);
- this.path = new LinkedList<LinkEvent>();
- for (Link link: path) {
- this.path.add(new LinkEvent(
- link.getSourceSwitch().getDpid(),
- link.getSourcePort().getNumber(),
- link.getDestinationSwitch().getDpid(),
- link.getDestinationPort().getNumber()));
- }
+ this.path = path;
this.bandwidth = bandwidth;
this.parentIntent = parentIntent;
}
@@ -50,25 +36,10 @@
return bandwidth;
}
- public List<LinkEvent> getPathByLinkEvent() {
+ public Path getPath() {
return path;
}
- /**
- * Get Path object.
- * @param graph
- * @return path object. If there is no path in the specified graph, returns null.
- */
- public Path getPath(NetworkGraph graph) {
- Path pathObj = new Path();
- for (LinkEvent linkEvent: path) {
- Link link = linkEvent.getLink(graph);
- if (link == null) return null;
- pathObj.add(link);
- }
- return pathObj;
- }
-
public Intent getParentIntent() {
return parentIntent;
}
diff --git a/src/main/java/net/onrc/onos/intent/PathIntentMap.java b/src/main/java/net/onrc/onos/intent/PathIntentMap.java
index b955922..d70def2 100644
--- a/src/main/java/net/onrc/onos/intent/PathIntentMap.java
+++ b/src/main/java/net/onrc/onos/intent/PathIntentMap.java
@@ -17,7 +17,7 @@
@Override
protected void putIntent(Intent intent) {
super.putIntent(intent);
- for (LinkEvent linkEvent: ((PathIntent) intent).getPathByLinkEvent()) {
+ for (LinkEvent linkEvent: ((PathIntent) intent).getPath()) {
HashSet<PathIntent> value = linkToIntents.get(linkEvent);
if (value == null)
value = new HashSet<PathIntent>();
@@ -29,7 +29,7 @@
@Override
protected void removeIntent(String intentId) {
PathIntent intent = (PathIntent) getIntent(intentId);
- for (LinkEvent linkEvent: intent.getPathByLinkEvent()) {
+ for (LinkEvent linkEvent: intent.getPath()) {
HashSet<PathIntent> value = linkToIntents.get(linkEvent);
value.remove(intent);
}
diff --git a/src/main/java/net/onrc/onos/intent/runtime/IPathCalcRuntimeService.java b/src/main/java/net/onrc/onos/intent/runtime/IPathCalcRuntimeService.java
index 9e53732..9491d67 100644
--- a/src/main/java/net/onrc/onos/intent/runtime/IPathCalcRuntimeService.java
+++ b/src/main/java/net/onrc/onos/intent/runtime/IPathCalcRuntimeService.java
@@ -4,6 +4,9 @@
import net.onrc.onos.intent.IntentMap;
import net.onrc.onos.intent.IntentOperationList;
+/**
+ * @author Toshio Koide (t-koide@onlab.us)
+ */
public interface IPathCalcRuntimeService extends IFloodlightService {
public IntentOperationList executeIntentOperations(IntentOperationList list);
public IntentMap getHighLevelIntents();
diff --git a/src/main/java/net/onrc/onos/intent/runtime/PathCalcRuntime.java b/src/main/java/net/onrc/onos/intent/runtime/PathCalcRuntime.java
index 4408f3f..95c63c8 100644
--- a/src/main/java/net/onrc/onos/intent/runtime/PathCalcRuntime.java
+++ b/src/main/java/net/onrc/onos/intent/runtime/PathCalcRuntime.java
@@ -7,11 +7,11 @@
import net.onrc.onos.intent.ConstrainedShortestPathIntent;
import net.onrc.onos.intent.Intent;
import net.onrc.onos.intent.IntentOperation;
+import net.onrc.onos.intent.IntentOperation.Operator;
import net.onrc.onos.intent.IntentOperationList;
import net.onrc.onos.intent.PathIntent;
import net.onrc.onos.intent.PathIntentMap;
import net.onrc.onos.intent.ShortestPathIntent;
-import net.onrc.onos.intent.IntentOperation.Operator;
import net.onrc.onos.ofcontroller.networkgraph.NetworkGraph;
import net.onrc.onos.ofcontroller.networkgraph.Path;
import net.onrc.onos.ofcontroller.networkgraph.Switch;
diff --git a/src/main/java/net/onrc/onos/intent/runtime/PathCalcRuntimeModule.java b/src/main/java/net/onrc/onos/intent/runtime/PathCalcRuntimeModule.java
index d72a13a..4c90a23 100644
--- a/src/main/java/net/onrc/onos/intent/runtime/PathCalcRuntimeModule.java
+++ b/src/main/java/net/onrc/onos/intent/runtime/PathCalcRuntimeModule.java
@@ -74,7 +74,7 @@
@Override
public void init(FloodlightModuleContext context) throws FloodlightModuleException {
datagridService = context.getServiceImpl(IDatagridService.class);
- networkGraphService = context.getServiceImpl(INetworkGraphService.class);
+ networkGraphService = context.getServiceImpl(INetworkGraphService.class);
}
@Override
diff --git a/src/main/java/net/onrc/onos/intent/runtime/PlanCalcRuntime.java b/src/main/java/net/onrc/onos/intent/runtime/PlanCalcRuntime.java
index 19a6b53..55cc475 100644
--- a/src/main/java/net/onrc/onos/intent/runtime/PlanCalcRuntime.java
+++ b/src/main/java/net/onrc/onos/intent/runtime/PlanCalcRuntime.java
@@ -17,12 +17,13 @@
import net.onrc.onos.intent.PathIntentMap;
import net.onrc.onos.intent.ShortestPathIntent;
import net.onrc.onos.ofcontroller.networkgraph.Link;
+import net.onrc.onos.ofcontroller.networkgraph.LinkEvent;
import net.onrc.onos.ofcontroller.networkgraph.NetworkGraph;
import net.onrc.onos.ofcontroller.networkgraph.Port;
import net.onrc.onos.ofcontroller.networkgraph.Switch;
/**
- *
+ *
* @author Brian O'Connor <bocon@onlab.us>
*
*/
@@ -32,20 +33,20 @@
protected PathIntentMap intents;
protected Set<Collection<FlowEntry>> flowEntries;
protected List<Set<FlowEntry>> plan;
-
+
public PlanCalcRuntime(NetworkGraph graph) {
this.graph = graph;
this.flowEntries = new HashSet<>();
this.plan = new ArrayList<>();
this.intents = new PathIntentMap();
}
-
+
public void addIntents(IntentOperationList intentOpList) {
intents.executeOperations(intentOpList);
computeFlowEntries();
constructPlan();
}
-
+
public List<Set<FlowEntry>> getPlan() {
return plan;
}
@@ -70,7 +71,8 @@
continue;
}
List<FlowEntry> entries = new ArrayList<>();
- for(Link link : intent.getPath(graph)) {
+ for(LinkEvent linkEvent : intent.getPath()) {
+ Link link = linkEvent.getLink(graph);
Switch sw = link.getSourceSwitch();
dstPort = link.getSourcePort();
FlowEntry fe = new FlowEntry(sw, srcPort, dstPort, srcMac, dstMac);
@@ -88,7 +90,7 @@
flowEntries.add(entries);
}
}
-
+
public void constructPlan() {
Map<FlowEntry, Integer> map = new HashMap<>();
for(Collection<FlowEntry> c : flowEntries) {
@@ -100,10 +102,10 @@
else {
i += 1;
}
-
+
}
}
-
+
// really simple first iteration of plan
//TODO: optimize the map in phases
plan.add(map.keySet());