@@ -0,0 +1,2298 @@
+package net.onrc.onos.intent;%0A%0Aimport java.util.HashMap;%0Aimport java.util.HashSet;%0Aimport java.util.LinkedList;%0A%0Aimport net.onrc.onos.ofcontroller.networkgraph.Link;%0Aimport net.onrc.onos.ofcontroller.networkgraph.Path;%0Aimport net.onrc.onos.ofcontroller.networkgraph.Switch;%0A%0A/**%0A * This class creates bandwidth constrained breadth first tree%0A * and returns paths from root switch to leaf switches%0A * which satisfies the bandwidth condition.%0A * If bandwidth parameter is not specified, the normal breadth first tree will be calculated.%0A * The paths are snapshot paths at the point of the class instantiation.%0A * @author Toshio Koide (t-koide@onlab.us)%0A */%0Apublic class ConstrainedBFSTree %7B%0A%09LinkedList%3CSwitch%3E switchQueue = new LinkedList%3CSwitch%3E();%0A%09HashSet%3CSwitch%3E switchSearched = new HashSet%3CSwitch%3E();%0A%09HashMap%3CSwitch, Link%3E upstreamLinks = new HashMap%3CSwitch, Link%3E();%0A%09HashMap%3CSwitch, Path%3E paths = new HashMap%3CSwitch, Path%3E();%0A%09Switch rootSwitch;%0A%09PathIntents intents = null;%0A%09Double bandwidth = null;%0A%0A%09public ConstrainedBFSTree(Switch rootSwitch) %7B%0A%09%09this.rootSwitch = rootSwitch;%0A%09%09this.intents = new PathIntents();%0A%09%09calcTree();%0A%09%7D%0A%0A%09public ConstrainedBFSTree(Switch rootSwitch, PathIntents intents, Double bandwidth) %7B%0A%09%09this.rootSwitch = rootSwitch;%0A%09%09this.intents = intents;%0A%09%09this.bandwidth = bandwidth;%0A%09%09calcTree();%0A%09%7D%0A%0A%09protected void calcTree() %7B%0A%09%09switchQueue.add(rootSwitch);%0A%09%09switchSearched.add(rootSwitch);%0A%09%09while (!switchQueue.isEmpty()) %7B%0A%09%09%09Switch sw = switchQueue.poll();%0A%09%09%09for (Link link: sw.getOutgoingLinks()) %7B%0A%09%09%09%09Switch reachedSwitch = link.getDestinationPort().getSwitch();%0A%09%09%09%09if (switchSearched.contains(reachedSwitch)) continue;%0A%09%09%09%09if (bandwidth != null && intents.getAvailableBandwidth(link) %3C bandwidth) continue;%0A%09%09%09%09switchQueue.add(reachedSwitch);%0A%09%09%09%09switchSearched.add(reachedSwitch);%0A%09%09%09%09upstreamLinks.put(reachedSwitch, link);%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D%0A%0A%09public Path getPath(Switch leafSwitch) %7B%0A%09%09Path path = paths.get(leafSwitch);%0A%09%09if (path == null && switchSearched.contains(leafSwitch)) %7B%0A%09%09%09path = new Path();%0A%09%09%09Switch sw = leafSwitch;%0A%09%09%09while (sw != rootSwitch) %7B%0A%09%09%09%09Link upstreamLink = upstreamLinks.get(sw);%0A%09%09%09%09path.add(0, upstreamLink);%0A%09%09%09%09sw = upstreamLink.getSourcePort().getSwitch();%0A%09%09%09%7D%0A%09%09%09paths.put(leafSwitch, path);%0A%09%09%7D%0A%09%09return path;%0A%09%7D%0A%7D%0A

Add ConstrainedBFSTree class