Thomas Vachuska
Committed by Brian O'Connor

GUI -- Fixing related-intents when device(s) are included in selection.

Change-Id: I736838c2e828a9a8cc81961980b9a9762be870f3
...@@ -22,7 +22,9 @@ import org.onosproject.net.Host; ...@@ -22,7 +22,9 @@ import org.onosproject.net.Host;
22 import org.onosproject.net.HostId; 22 import org.onosproject.net.HostId;
23 import org.onosproject.net.Link; 23 import org.onosproject.net.Link;
24 import org.onosproject.net.device.DeviceService; 24 import org.onosproject.net.device.DeviceService;
25 +import org.onosproject.net.flow.FlowRule;
25 import org.onosproject.net.host.HostService; 26 import org.onosproject.net.host.HostService;
27 +import org.onosproject.net.intent.FlowRuleIntent;
26 import org.onosproject.net.intent.HostToHostIntent; 28 import org.onosproject.net.intent.HostToHostIntent;
27 import org.onosproject.net.intent.Intent; 29 import org.onosproject.net.intent.Intent;
28 import org.onosproject.net.intent.IntentService; 30 import org.onosproject.net.intent.IntentService;
...@@ -34,8 +36,10 @@ import org.onosproject.net.intent.PointToPointIntent; ...@@ -34,8 +36,10 @@ import org.onosproject.net.intent.PointToPointIntent;
34 import org.onosproject.net.link.LinkService; 36 import org.onosproject.net.link.LinkService;
35 37
36 import java.util.ArrayList; 38 import java.util.ArrayList;
39 +import java.util.Collection;
37 import java.util.HashSet; 40 import java.util.HashSet;
38 import java.util.List; 41 import java.util.List;
42 +import java.util.Objects;
39 import java.util.Set; 43 import java.util.Set;
40 44
41 import static org.onosproject.net.intent.IntentState.INSTALLED; 45 import static org.onosproject.net.intent.IntentState.INSTALLED;
...@@ -59,8 +63,7 @@ public class TopologyViewIntentFilter { ...@@ -59,8 +63,7 @@ public class TopologyViewIntentFilter {
59 * @param hostService host service reference 63 * @param hostService host service reference
60 * @param linkService link service reference 64 * @param linkService link service reference
61 */ 65 */
62 - TopologyViewIntentFilter(IntentService intentService, 66 + TopologyViewIntentFilter(IntentService intentService, DeviceService deviceService,
63 - DeviceService deviceService,
64 HostService hostService, LinkService linkService) { 67 HostService hostService, LinkService linkService) {
65 this.intentService = intentService; 68 this.intentService = intentService;
66 this.deviceService = deviceService; 69 this.deviceService = deviceService;
...@@ -175,6 +178,11 @@ public class TopologyViewIntentFilter { ...@@ -175,6 +178,11 @@ public class TopologyViewIntentFilter {
175 if (pathContainsDevice(pathIntent.path().links(), device.id())) { 178 if (pathContainsDevice(pathIntent.path().links(), device.id())) {
176 return true; 179 return true;
177 } 180 }
181 + } else if (installable instanceof FlowRuleIntent) {
182 + FlowRuleIntent flowRuleIntent = (FlowRuleIntent) installable;
183 + if (rulesContainDevice(flowRuleIntent.flowRules(), device.id())) {
184 + return true;
185 + }
178 } else if (installable instanceof LinkCollectionIntent) { 186 } else if (installable instanceof LinkCollectionIntent) {
179 LinkCollectionIntent linksIntent = (LinkCollectionIntent) installable; 187 LinkCollectionIntent linksIntent = (LinkCollectionIntent) installable;
180 if (pathContainsDevice(linksIntent.links(), device.id())) { 188 if (pathContainsDevice(linksIntent.links(), device.id())) {
...@@ -186,7 +194,7 @@ public class TopologyViewIntentFilter { ...@@ -186,7 +194,7 @@ public class TopologyViewIntentFilter {
186 return false; 194 return false;
187 } 195 }
188 196
189 - // Indicates whether the specified intent involves the given device. 197 + // Indicates whether the specified links involve the given device.
190 private boolean pathContainsDevice(Iterable<Link> links, DeviceId id) { 198 private boolean pathContainsDevice(Iterable<Link> links, DeviceId id) {
191 for (Link link : links) { 199 for (Link link : links) {
192 if (link.src().elementId().equals(id) || link.dst().elementId().equals(id)) { 200 if (link.src().elementId().equals(id) || link.dst().elementId().equals(id)) {
...@@ -196,6 +204,16 @@ public class TopologyViewIntentFilter { ...@@ -196,6 +204,16 @@ public class TopologyViewIntentFilter {
196 return false; 204 return false;
197 } 205 }
198 206
207 + // Indicates whether the specified flow rules involvesthe given device.
208 + private boolean rulesContainDevice(Collection<FlowRule> flowRules, DeviceId id) {
209 + for (FlowRule rule : flowRules) {
210 + if (rule.deviceId().equals(id)) {
211 + return true;
212 + }
213 + }
214 + return false;
215 + }
216 +
199 private boolean isIntentRelevant(PointToPointIntent intent, 217 private boolean isIntentRelevant(PointToPointIntent intent,
200 Iterable<ConnectPoint> edgePoints) { 218 Iterable<ConnectPoint> edgePoints) {
201 for (ConnectPoint point : edgePoints) { 219 for (ConnectPoint point : edgePoints) {
...@@ -226,6 +244,9 @@ public class TopologyViewIntentFilter { ...@@ -226,6 +244,9 @@ public class TopologyViewIntentFilter {
226 Iterable<Intent> intents) { 244 Iterable<Intent> intents) {
227 Link ccSrc = getFirstLink(opticalIntent.getSrc(), false); 245 Link ccSrc = getFirstLink(opticalIntent.getSrc(), false);
228 Link ccDst = getFirstLink(opticalIntent.getDst(), true); 246 Link ccDst = getFirstLink(opticalIntent.getDst(), true);
247 + if (ccSrc == null || ccDst == null) {
248 + return false;
249 + }
229 250
230 for (Intent intent : intents) { 251 for (Intent intent : intents) {
231 List<Intent> installables = intentService.getInstallableIntents(intent.key()); 252 List<Intent> installables = intentService.getInstallableIntents(intent.key());
...@@ -234,8 +255,8 @@ public class TopologyViewIntentFilter { ...@@ -234,8 +255,8 @@ public class TopologyViewIntentFilter {
234 List<Link> links = ((PathIntent) installable).path().links(); 255 List<Link> links = ((PathIntent) installable).path().links();
235 if (links.size() == 3) { 256 if (links.size() == 3) {
236 Link tunnel = links.get(1); 257 Link tunnel = links.get(1);
237 - if (tunnel.src().equals(ccSrc.src()) && 258 + if (Objects.equals(tunnel.src(), ccSrc.src()) &&
238 - tunnel.dst().equals(ccDst.dst())) { 259 + Objects.equals(tunnel.dst(), ccDst.dst())) {
239 return true; 260 return true;
240 } 261 }
241 } 262 }
......